In this post I’ll go over how to install Ruby on Rails on Linux using Ruby Version Manager, or RVM.

RVM simplifies maintaining one or more independent Ruby environments, which can be helpful for development and testing. You can run builds on multiple gemsets this way, and if you so choose you can set up self-contained environments for each project.

Express install, using default Rails environment:

Step 1: First we’ll download the keychain for verifying our download, and install curl.

Curl is an information transfer tool that supports many file transfer protocols, and we’ll use it to get the latest version of rvm.

gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
sudo apt-get install curl

Step 2: Now we can use curl to install RVM. For the express install I’ll assume we want the default version of rails, and add the –rails argument to install it automatically.

\curl -L https://get.rvm.io | bash -s stable --rails

Step 3: Finally, let’s add a line to our .bashrc file to ensure we can access ruby, rails, rake and more from terminal.

leafpad ~/.bashrc

Add “source $HOME/.rvm/scripts/rvm” to the end of your .bashrc file and save your changes.

Run “source ~/.bashrc”. You should now have access to your Ruby on Rails tools.

alt-text

Custom install, using specific Ruby versions:

Step 1: As before, we’ll download the keychain for verification and install curl.

gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
sudo apt-get install curl

Step 2: This time we’ll set a specific Ruby version.

\curl -L https://get.rvm.io | bash -s stable --ruby=SPECIFIED_VERSION

Step 3: As before, add “source $HOME/.rvm/scripts/rvm” to the end of your ~/.bashrc file, and run “source ~/.bashrc”.

Since we only installed Ruby and not Rails, let’s install the Rails gem ourselves.

gem install rails

Adding or switching between Ruby environments:

rvm list                        # view installed environments
rvm list known                  # view Ruby versions available to install
rvm use SPECIFIED_VERSION       # switch to an environment for the current session
rvm use --default SPECIFIED_VERSION # switch to an environment for this and future sessions
rvm install SPECIFIED_VERSION   # install a new environment
rvm uninstall SPECIFIED_VERSION # remove an environment

You can find additional information in the RVM documentation, linked below.

Helpful resources: