How to install multiple Ruby versions on ubuntu using RVM ?

Most of the ruby enthusiasts are now moving on to Rails 3.0, but there is always something from the past application which holds us back. So here is some help for you to set it up on Ubuntu:

RVM is solution for this, to install RVM just follow below steps:

Dependencies of RVM:

sudo apt-get install openssl
sudo apt-get install curl
sudo apt-get install git-core

Make sure all the above dependencies are installed, lets see how to install rvm next

Open the terminal and type below command

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

RVM in installed. check the version using “rvm -v”

Once above step is complete, open file .bashrc and add following line at the last

[[ -s "/usr/local/rvm/scripts/rvm" ]] && source "/usr/local/rvm/scripts/rvm"
# This loads RVM into a shell session.

For more information check “rvm -notes” or “rvm –help”

Now install Ruby versions
Install Ruby-1.8.7

sudo rvm install 1.8.7

Install Ruby-1.9.2

sudo rvm install 1.9.2

If you get following error while installing ruby

**Installing Ruby from source to: /Users/mark/.rvm/rubies/ruby-1.9.2-p290, this may take a while depending on your cpu(s)...
ruby-1.9.2-p290 - #fetching 
ruby-1.9.2-p290 - #downloading ruby-1.9.2-p290, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0Warning: Failed to create the file ruby-1.9.2-p290.tar.bz2: Permission denied
  0 8604k    0 16150    0     0  14980      0  0:09:48  0:00:01  0:09:47 26562
curl: (23) Failed writing body (0 != 16150)
ERROR: There was an error, please check /Users/mark/.rvm/log/ruby-1.9.2-p290/*.log. Next we'll try to fetch via http.
Trying http:// URL instead.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0Warning: Failed to create the file ruby-1.9.2-p290.tar.bz2: Permission denied
  0 8604k    0 16150    0     0  24640      0  0:05:57 --:--:--  0:05:57 28333
curl: (23) Failed writing body (0 != 16150)
ERROR: There has been an error while trying to fetch the source.  
Halting the installation.
ERROR: There has been an error fetching the ruby interpreter. Halting the installation.**

Then this issue is because of no permissions, to give proper permissions do the following step
chown -R user:user /usr/local/rvm where user is your logged in user

Now try again installing Ruby.

To set default ruby version type

sudo rvm use 1.9.2 --default

To install specific rubygems version, use following command:

rvm rubygems 1.3.7

Now install rails

sudo gem install rails --version=3.0.3 --no-ri --no-rdoc

All set now. Just make sure everything is pointing to correct path:

which ruby 
/usr/local/rvm/bin/ruby

which rails
/usr/local/rvm/gems/ruby-1.9.2-p180/bin/rails

which gem
/usr/local/rvm/bin/gem

To check version type below commands

gem -v
ruby -v
rails -v
rvm -v

For more information refer this link https://rvm.beginrescueend.com/rvm/install

Leave a comment