Friday 18 May 2012

Using RVM with different versions of Rails on Mac OSX

I had to use both jRuby and Ruby with different versions of Rails on the same machine which turned out to be quite a frustration. I've heard about RVM which separates Ruby environments together with their gems from one another. I decided to give it a shot...
RVM installation (stable version)
  1. first lets install the RVM
    curl -L get.rvm.io | bash -s stable 
  2. after installation we'll have to reload the console and run:
    source ~/.rvm/scripts/rvm
  3. test if everything was OK
    type rvm | head -n 1 
    to get the message rvm is a function
Ruby installation 

I will be using jRuby 1.6.5 and Ruby 1.9.3 so we need to install those two:
rvm install  1.6.5
rvm install  1.9.3 
After installations finish, run rvm list to get the list of installed rubies.
I will use jRuby and set it as default as I use it most of the time:
rvm use 1.6.5 --default

Rails installation

First we'll need Gemsets. They can be regarded as folders with separate ruby setups, gems and irb, all separate and self-contained - from the system, and from each other.
Lets create one for the Rails we require 2.3.8
rvm gemset create rails238
rvm use 1.6.5@rails238

To install rails and remaining gems we can use gem install but since I use geminstaller we can just run this gem and it does the job for us.
gem install geminstaller
geminstaller

Before we can start anything we have to set path for our new jRuby in .profile and refresh it
with source ~/.profile.
At the end we can override rvmrc to load this gemset automatically:
rvm --rvmrc --create 1.6.5@rails238

For Rails 3.2, which I will use with Ruby,  the gemset stuff is same as before except I'll use bundle install.

We'll these are my notes for RVM installation. Off to checkout Pry, heard it's way better than IRB....