How to install RVM on MacOS X Snow Leopard

anand posted this on 30 Dec 2010

Managing multiple versions of rubies and ruby gems is a very difficult task. One of your projects might be using Ruby 1.9.2, while your other old project might be using Ruby 1.8.7. Adding to this complexity, each of your project might be using different versions of a same ruby gem. (For example rails 3.0.1, rails 2.3.8, rails 2.3.5).

RVM was created to solve this problem. RVM is surprisingly easy to use with its simple set of commands. I will explain how to use it in the next blog post. Here, I will explain how to install it.

Before installing rvm, make sure that you have installed XCode developer tools in your mac. Apple distributes the XCode developer tools in CD with every Mac. You can even download it from Apple developer site for free.

To Install RVM

1. Open your terminal, copy and paste the following command in it. Then press enter.

bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )


2. Then, go to your home directory

cd

3. Edit your .profile file using your favorite editor.

nano ~/.profile

4. Copy and paste the below line at the end of .profile file

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.

5. Save it and exit the file. (This step varies for different editors. For nano it is Ctrl-o and then Ctrl-x )

6. Run the following command to reload your shell settings.

source ~/.profile

7. Confirm whether rvm was installed properly in your system by typing the following command in terminal.

type rvm | head -1


You should see the following output.

rvm is a function

Your rvm is installed now.

Installing Rubies:

Ruby-1.8.7-p174 (Ruby 1.8.7 patch level 174) is installed by default in MacOSX. This is called system ruby. If you want to check its version in your mac, you can type this command and see for yourself.

ruby -v

Now, lets install ruby 1.8.7 and ruby 1.9.2 using RVM.

1. To install ruby 1.8.7, type this command in your terminal.

rvm install 1.8.7

Now, rvm will download ruby v1.8.7 source code, compile and install it automatically. This process will take some time depending on your system and internet speed.

2. Installing ruby 1.9.2 is by the same command.

rvm install 1.9.2

Note: Installing MacRuby, JRuby is similar with a few tweaks. You can refer the documentation for installing them.

After installing, you can check by typing the following command


rvm list

and it will give the following output for me.

rvm rubies

jruby-1.5.3 [ x86_64-java ]
macruby-0.7.1 [ x86_64 ]
=> ruby-1.8.7-p302 [ x86_64 ]
ruby-1.9.2-p0 [ x86_64 ]
The output shows the list of rubies that are installed in my system and the little arrow shows the version I'm using currently i.e ruby-1.8.7-p302 [ x86_64 ] .

Using Rubies:


To start using ruby 1.8.7, you need to give this command in terminal,

rvm use 1.8.7


and to start using 1.9.2, you need to give a similar command

rvm use 1.9.2

To make one ruby version as default, you need to give command like

rvm use 1.9.2 --default


You can always check the version you are using currently by one of the following commands.

rvm list


or

ruby -v

Please refer the documentation for more advanced use cases.

~