Skip to content

Setting Ruby to version 1.9.2 as default in Mac OS X Lion

August 14, 2011

After installing version 1.9.2 of Ruby I suffered a little bit to get RVM (Ruby Version Manager) to use version 1.9.2 as the default version of Ruby in Terminal. These are the steps I followed to get it to work correctly:

Install RVM and edit Profile scripts

If you haven’t done so, install Ruby Version Manager (RVM). First, use the following bash script to install RVM:

bash << (curl -s https://rvm.beginrescueend.com/install/rvm)

Usually, in Mac OS X environments the Terminal.app uses bash. Therefore your Terminal startup scripts are set to use .bash_profile and .bashrc. In order to avoid confusion, it’s better to use one or the other. Modify your .bash_profile file using your favorite text editor (if you would like to open the file from Finder install Tinker Tools first so that you can see all hidden files and directories in Finder). Add the following to your .bash_profile file so that it calls the .bashrc file automatically when you open a Terminal session:

a) Edit .bash_profile:

if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi

b) Now edit .bahsrc:

Add the following to the end of your .bashrc file:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
[[ -r $rvm_path/scripts/completion ]] && . $rvm_path/scripts/completion #rvm tab completion

c) Add PATHs, this is important because if you don’t have the right PATHs when using Terminal you won’t be able to use profile specific applications (such as Ruby) that you have installed from within your profile. As an example I have copied and pasted my own PATHs section:

export PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin:$HOME/.rvm/gems/ruby-1.9.2-p290/bin:$HOME/.rvm/scripts/rvm:/Developer/usr/bin:/Developer/usr/libexec:/Developer/usr/sbin:
/Developer/usr/local/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:$HOME/bin:
/usr/libexec:/usr/local/git:/usr/local/mysql/bin

export CC=gcc-4.2

Set Ruby to default to version 1.9.2

First, make sure that the system version of Ruby is ok:

$ ruby -v

That should return your system Ruby version, which as of this writing is 1.8.7 with Mac OS X Leopard and Mac OS X Lion.

ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]

Now, let’s use RVM to se the default Ruby interpreter to 1.9.2:

$ rvm -default use 1.9.2

Now type ruby -v again and that should return version 1.9.2:

$ ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.0.0]

This should save you a few headaches, it’s a pain to have to type $ ruby use 1.9.2 every time you open a Terminal.

About these ads
5 Comments
  1. Jenny permalink

    Thanks! I actually set my default (before this post) to “$ ruby use 1.9.2″

  2. Hi, just letting you know that if you use this command with 10.8.2 you should add an extra “-” in front of default in order for it to work. The command ends up looking like dvm –default use 1.9.3

  3. Correction, rvm –default use 1.9.3

    • Thanks Gabriele will correct the post. It has been a while perhaps I need to publish a new version :-) )

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 79 other followers

%d bloggers like this: