Updated: Managing multiple Ruby versions on OS X
Turns out there's an easier way to manage the multiple ruby versions on OS X with Ruby Version Manager (rvm).
1. Follow the rvm installation instructions here. I used the recommended installation from the GitHub repository.
2. Install the version of ruby you want:
> [dahlia@rogue ~]> rvm install 1.9.2
3. Setting up your default ruby version.
-- Find out the list of rubies that you have installed:
> [dahlia@rogue ~]> rvm list
rvm rubies
ruby-1.9.2-rc2 [ x86_64 ]
-- Set the default version of ruby:
> [dahlia@rogue ~]> rvm --default ruby-1.9.2-rc2
-- Verify that it was setup correctly:
> [dahlia@rogue ~]> which ruby
/Users/dahlia/.rvm/rubies/ruby-1.9.2-rc2/bin/ruby
4. And you're done!
Hope this helps.
Managing multiple Ruby versions on OS X
Managing multiple versions of Ruby hasn't been completely straightforward on the Mac. Dan Manges wrote a very helpful blog post about 2.5 years ago on how to manually manage those multiple Ruby versions but I recently found out about RVM (Ruby Version Manager) which is a command line tool that lets you install and switch between versions of Ruby in a less hairy way. My joys however were dampened when I found out that RVM isn't quite smart enough to completely migrate you over to your desired Ruby version. I sorta solved my problems with a combination of RVM and Dan's instructions. If someone out there has a better suggestion, I'm more than happy to hear it.
The RVM instructions here assume that your environment will be switched over when you install a new version of Ruby. However, OS X has a symlink set up to point to the bundled Ruby framework which you either have to remove or re-point somewhere else.
$ ls -l /usr/bin/ruby
/usr/bin/ruby -> /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby
RVM installs Ruby versions into the ~/.rvm/rubies directory.
$ rvm install 1.8.7
Installing Ruby from source to: /Users/dbock/.rvm/rubies/ruby-1.8.7-p249
$ rvm install 1.9.1
Installing Ruby from source to: /Users/dbock/.rvm/rubies/ruby-1.9.1-p378
Since OS X is a little funny when it comes to managing Ruby installations, I did the following:
1. Create a symlink to point to the version of Ruby that I want:
$ ln -s ~/.rvm/rubies/ruby-1.9.1-p378 /usr/local/ruby
$ ls -l /usr/local/ruby
Mar 16 09:46 /usr/local/ruby -> /Users/dbock/.rvm/rubies/ruby-1.9.1-p378
2. Add that symlink to the Path, and make sure it comes before any other Ruby installation.
export PATH=/usr/local/ruby/bin:/opt/local/bin:/opt/local/sbin:$PATH
3. Remove OS X default Ruby symlink, and re-direct the bundled Ruby installation to point to my current version.
$ rm /usr/bin/ruby
$ ln -s ~/.rvm/rubies/ruby-1.9.1-p378 /System/Library/Frameworks/Ruby.framework/Versions/Current/usr
You could create aliases to be included in your ~/.bash_profile to make switching between the versions a little easier and Dan also mentions them. Here are the ones that I used:
alias ruby191=~/.rvm/rubies/ruby-1.9.1-p378/bin/ruby
alias ruby187=~/.rvm/rubies/ruby-1.8.7-p249/bin/ruby
alias use_ruby_191='sudo ln -fhs ~/.rvm/rubies/ruby-1.9.1-p378 /usr/local/ruby'
alias use_ruby_187='sudo ln -fhs ~/.rvm/rubies/ruby-1.8.7-p249 /usr/local/ruby'