Installing and setting up RVM (Ruby Version Manager)

Sometime last month I had to set up a Rails 3 app on a RHEL5 server. From what I have experienced so far, Redhat is a shit server especially when it comes to updated libraries… thats just the point.. they’re not updated. It’s like whoever works on the Redhat packages/libraries is always a step behind. In this particular case, the ruby version provided by Redhat’s software channel was 1.8.6… can you believe that crap??? I didn’t complain earlier on because most of my apps on that particular server were running on Rails 2.3 so no drama. But Rails 3 need ruby 1.8.7 or 1.9.2 or later. I’m sure you’re wondering “why didn’t he just build it from source”…. well I did but on my third try I decided it was overkill.. the installation had so many dependencies missing (maybe redhat also has to blame) and when I thought it had finally worked, Ruby was ‘halfway’ working (sigh) ruby tcl/tk support was compromised and on other tries some other libraries were causing ruby to function erroneously. Then came the saviour (cue orchestra music and shut eyes for bright white light) RUBY VERSION MANAGER

I have to say, this is singl;e-handedly one of the most amazing ruby tools I have ever used. It is just breathtaking that someone created such a useful piece of software. RVM enables you to install different versions of Ruby on it. It is basically a wrapper for Ruby installations that is independent from your system Ruby. The cool thing is you are installing Ruby from,through and into RVM. It takes care of the whole process; just tell you what Ruby you want and it will get it and set it up for you. All you need is to select which one you want to use and it has other cooler features like gemsets that allow you to compartmentalize your rails installations with their gems… fuckin amazing!!

Anyway, enough rambling… here are the steps I went through:

Installation
1. It is recommended to install RVM from the github repository:

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

2. Then put the following into your ~/.bash_profile at the end

[[ -s “$HOME/.rvm/scripts/rvm” ]] && . “$HOME/.rvm/scripts/rvm”

Doing so ensures rvm is loaded as a function (versus as a binary), ensuring commands such as      rvm use work as expected

3. Confirm that this worked by opening a new shell (or restart the server) and running:

$ type rvm | head -1

On success, it should output:

rvm is a function

RVM’s most compelling feature is that it caters for six different distributions out of the box (MRI 1.8.6, MRI 1.8.7, 1.9.1, 1.9.2, Ruby Enterprise Edition 1.8.6, JRuby 1.3.1)

To install a ruby version on RVM, do the following e.g for ruby 1.8.7

rvm install ruby-1.8.7-p334

If you would like to make one specific Ruby be the default ruby that is selected when you open a new terminal shell, use the –default flag

rvm –default use 1.8.7

Output:

Using /usr/local/rvm/gems/ruby-1.8.7-p334

If you also check the version in the normal way it should output rvm’s default ruby version:

ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]

Other stuff you can do
To switch back to your system ruby:

$ rvm use system
Now using system ruby.
$ ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [x86_64-linux]

To switch back to RVM’s default ruby:

$ rvm default

$ ruby -v

ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]

To show what ruby is currently the selected default:

$ rvm list default

Default Ruby (for new shells)

ruby-1.8.7-p334 [ x86_64 ]

If you wish to switch back to your system ruby as default, remember that RVM does not “manage” the system ruby and is “hands off”.
This means to set the “system” ruby as default, you reset RVM’s defaults as follows.

$ rvm reset

Installing  Passenger
N/B Bear in mind that if you’re installing Rails 3 like I was, you’re current passenger instalation is using the system’s ruby version. Install passenger 3:

$ gem install passenger

Then:
$ passenger-install-apache2-module

The installation will give you the lines you are supposed to add to your apache configuration file. These lines will ensure passenger uses your RVMs ruby and not the system’s.

There is much more to learn on RVM. It has many more features. I will post something on gemsets in future but for now you can get all the in formation you want at http://beginrescueend.com/

Did this waste your time or did you benefit from it? Let me know :-) Feel free to add your own views too