RVM - Ruby Version Manager

Ruby is a very popular programming language that has Ruby on Rails or RoR is a popular development framework that allows you to easily get your application up and running with minimal hassle.

Developing applications often times requires that you emulate different environments. Different versions of Ruby may be necessary for different projects. With conventional installations, this would impede your ability to be flexible.

Luckily, the Ruby Version Manager, known more widely as RVM, allows you to easily install multiple, contained versions of Ruby and easily switch between them.

Installing RVM
Run a quick update to make sure that all of the packages we download to our VPS are up to date:
sudo apt-get update

If you do not have curl on your system, you can start by installing it:
sudo apt-get install curl

To install RVM:
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

To inject RVM into your environment .bashrc add the bit of bash it mentions at the end of the installation:
echo ‘[[ -s “$HOME/.rvm/scripts/rvm” ]] && source “$HOME/.rvm/scripts/rvm”’ >> .bashrc

Installing Ruby
Let’s go ahead and install Ruby MRI 1.9.3 (this is the default interpreter originally developed by Matz) first, and set that as our default interpreter. Afterwards, we’ll install Ruby 1.8.7, use RVM to easily switch between these two Rubies.
Intall ruby version 1.9.3:
rvm install 1.9.3

To verify it works:
ruby -v

To make ruby version 1.9.3 as default version:
rvm —default 1.9.3

Let’s install ruby version 1.8.7:
rvm install 1.8.7

To switch ruby version:
rvm use 1.8.7 or rvm 1.8.7

Installing Rails
To install the latest Rails:
gem install rails

One common way to distribute code in Ruby is to use a format called gems. Gems can be installed to extend the capabilities of the core Ruby distribution, and there are often gems that are required to be installed to get certain programs to function correctly.

In keeping with RVM’s mission of providing contained Ruby environments, it is also possible to install gems that are only associated with a single Ruby installation. RVM calls this functionality gemsets.

This means that you can have two different versions of the same gem, or you can make gems unaware of other gems on the system.

To see the available gemsets for the current Ruby:
rvm gemset list

If you have more than one Ruby version installed, you can see all of the gemsets:
rvm gemset list_all

By default, you should have two gemsets configured:
– default: the gemset that is applied if no other gemset is specified.
– global: this gemset is inherited by every other gemset that is used. This set generally does not need to be selected because it will be included automatically. You should install shared gems here.

Creating Gemset for Rails Project
1. Create a Rails project:
rails new blog

2. Get in the project:
cd blog

3. Create gemset for the project:
rvm —rvmrc —create ruby_version@gemset_name
rvm —rvmrc —create 1.9.3@blog

4. Get out the project:
cd ..

5. Get in the project:
cd blog

6. To see the gemset that we have created and stand on:
rvm gemset list

So far so good whenever we cd into the project it will automatically switch to project’s gemset.