Use Rvm to manage Ruby and Rails version

20 Jul 2013

Install Rvm


$ curl -L get.rvm.io | bash -s stable
$ source ~/.bashrc
$ source ~/.bash_profile

Use Rvm to install Ruby


$ rvm install 2.1.1
$ rvm use 2.1.1 --default # set ruby-2.1.1 as default

Create specific gemset

Sometimes we need different ruby & rails version for different project, so we can create multiple environments for specific project.

Example-1: Project-1 use ruby-1.9.2 & rails-3


$ rvm install 1.9.2
$ rvm use 1.9.2
$ rvm gemset create rails3

# create a file '.rvmrc' in Project-1/, content is: 
rvm use ruby-1.9.2-p320@rails3 

Done! now when we go to folder Project-1/, rvm will use gemset rails3 automatically.

Example-2: Project-2 use ruby-2.1.1 & rails-4


$ rvm install 2.1.1
$ rvm use 2.1.1
$ rvm gemset create rails4

# create a file '.rvmrc' in Project-2/, content is 
rvm use ruby-2.1.1@rails4 

Done! now when we go to folder Project-2/ rvm use gemset rails4 automatically.

Reference


http://ruby-china.org/wiki/rvm-guide