rbenv and rubygems on a osx installation

Edit:

I had tried to install on Ubuntu, I had to install some extra packages to build ruby,

$ sudo apt-get install build-essential zlib1g zlib1g-dev zlibc libxml2 libxml2-dev libxslt-dev libssl-dev

End Edit;

I really like rvm because it has lots of great features and I never had a problem with it when I used it, but I wanted to give rbenv a try. Finally, I had a fresh installation of Lion to try it on. I followed all the steps found in the rbenv wiki, followed by downloading and installing the latest version of Ruby and RubyGems.

The following are my steps that I want to use as a reminder of what I did. I opted not to install via homebrew, which would probably have been easier, but I always like doing things the hard way first to figure out how it all works. I also had to install xcode, in order to compile new gems and ruby versions.

Installing rbenv:

~ $ git clone git://github.com/sstephenson/rbenv.git .rbenv
~ $ echo 'export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"' >> ~/.zshrc
~ $ echo 'eval "$(rbenv init -)"' >> ~/.zshrc
~ $ source ~/.zshrc

That’s it for install rbenv, now I need to install ruby.

Since I opted to install rbenv the hard way, I also opted not to install ruby-build, and download the ruby source directly from http://ruby-lang.org. I got ruby-1.9.2-p290 and ruby-1.8.7-p352 tarballs.

Installing ruby:

~/Downloads/ruby-1.9.2-p290 $ ./configure --prefix=$HOME/.rbenv/versions/1.9.2-p290
~/Downloads/ruby-1.9.2-p290 $ make && make install

Refresh rbenv after installing gems and ruby versions:

~ $ rbenv rehash

I check the version available, and then set my global preference to the latest installed version:

~ $ rbenv versions
  1.9.2-p290
~ $ rbenv global 1.9.2-p290
~ $ rbenv versions
* 1.9.2-p290

Next, I wanted to install the bundler gem, but I found out that by default ‘gem’ executable is pointing to the OSX version. After confirming I was installing into the right version of ruby, I needed to download and install rubygems.

~/Downloads/rubygems-1.8.10 $ ruby --version
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.1.0]
~/Downloads/rubygems-1.8.10 $ ruby setup.rb

Then I need to rebuild the rbenv shim binaries to get the gem executable.

~ $ rbenv rehash

That’s it. I double checked the gem version I was running:

~ $ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.10
  - RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [x86_64-darwin11.1.0]
  - INSTALLATION DIRECTORY: /Users/beverlyguillermo/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: /Users/beverlyguillermo/.rbenv/versions/1.9.2-p290/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/beverlyguillermo/.rbenv/versions/1.9.2-p290/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-11
  - GEM PATHS:
     - /Users/beverlyguillermo/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1
     - /Users/beverlyguillermo/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

Happy with all of that, I installed any gems I wanted. Yea, rbenv!

vmware, ubuntu, and shared folders

I use VMWare Fusion a lot, simply because I like to replicate the server configurations on my local development machine and it’s easier to have multiple instances of servers readily available with it. I also like to have my code available at all times with whichever VM I am using, so the code is shared. One thing I notice is that the VMTools defaults to using Mac’s UID/GID information, rather than the equivalent on the VM. So using these comments, I found a way to make the changes.

First, I double checked /etc/mtab to find out how it’s mounted.

$ vim /etc/mtab

and it looks like this in that file on my machine:

.host:/ /mnt/hgfs vmhgfs rw,ttl=1 0 0

I copied that and edited the /etc/fstab file and added the UID/GID for my user or whatever existing user or group. I also got from the comments that it fails mounting automatically, and that I should also add nobootwait to the parameters and manually perform unmount and mount. It really sucks but that’s what you got to deal with for the flexibility of multiple development OSes.

$ vim /etc/fstab

In the file, I added:

.host:/ /mnt/hgfs vmhgfs rw,ttl=1,uid=1000,gid=1000,nobootwait 0 0

When you restart the VM, you’ll get some errors (if you’re using the GUI, you probably won’t see it), but login and then do the following:

# umount /mnt/hgfs
# mount /mnt/hgfs

Create a script per the comments if you want. It saved me a lot of time.

Using Ubuntu, Nginx, FastCGI, Python, and Django

NOTE: No security on the following, this was for development purposes just to learn python and django.

From a fresh install of Ubuntu Meerkat (10.10), I added the following packages:

  1. python
  2. python-flup
  3. python-mysqldb
  4. nginx

After making sure, python is installed and installing the django framework sdk. I check to make sure django will use fastCGI by running the following:

$ cd [path to django project root]
$ python manage.py runfcgi host=127.0.0.1 port=8080 --settings=settings

And to kill the process:

$ pkill -f "python manage.py runfcgi host=127.0.0.1 port=8080 --settings=settings"

Next, is to edit nginx configuration, adding the new django site to nginx’s sites-enabled directory:

  server {
    listen 80; 
    server_name localhost;
 
    location ~* ^.+.(js|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov) {
      rroot /media/;
      access_log   off;
      expires      30d;
    }   
    location / { 
          # host and port to fastcgi server
          fastcgi_pass 127.0.0.1:8080;
          fastcgi_param PATH_INFO $fastcgi_script_name;
          fastcgi_param REQUEST_METHOD $request_method;
          fastcgi_param QUERY_STRING $query_string;
          fastcgi_param CONTENT_TYPE $content_type;
          fastcgi_param CONTENT_LENGTH $content_length;
          fastcgi_pass_header Authorization;
          fastcgi_intercept_errors off;
      }   
      access_log  /var/log/nginx/localhost.access_log main;
      error_log  /var/log/nginx/localhost.error_log;
  }

Then, restarting nginx and then trying to access the site via the regular port 80 access.

Upgrading to the latest linux distro version

If you upgrade your distro over the network like I do, reboot and then see the console say something like this:

mountall:/proc: unable to mount: Device or resource busy
mountall:/proc/self/mountinfo: No such file or directory
mountall: root filesystem isn’t mounted
init: mountall main process (736) terminated with status 1
General error mounting filesystems.
A maintenance shell will now be started.
CONTROL-D will terminate this shell and re-try.
Give root password for maintenance
(or type Control-D to continue):

Upgrade your linux kernel is greater than or equal to 2.6.26.8 — or else you’ll have a panic attack like I did. I’m so lucky that my service provider had it and could do it automatically.