1.6. Ubuntu 12.04 LTS - Installation of Ruby on Rails 3.2 with RVM

There are two main reasons for installing a Ruby on Rails system with RVM (Ruby Version Manager):
  • You simply do not have any root rights on the system. In that case, you have no other option.
  • You want to run several Rails systems that are separated cleanly, and perhaps also separate Ruby versions. This can be easily done with RVM on the Linux system. Then you can run Ruby 1.8.7 with Rails 2.3.8 and in parallel Ruby 1.9.3 with Rails 3.0 on the same computer.


Detailled information on RVM can be found on the RVM homepage at https://rvm.io/.
This description assumes that you have a freshly installed Ubuntu 12.04 LTS. You can find an ISO image for the installation at http://www.ubuntu.com/.


If you are reading the printed book version of this chapter, then please also check the online version at http://xyzpub.com/en/ruby-on-rails/3.2/. Each update of the operating system or RVM will usually mean an update of the installation instructions.


If you have root or sudo rights on the target system, you can use the following commands to ensure that all required programs for a successful installation of RVM are available. If you do not have root rights, you have to either hope that your admin has already installed everything you need, or send them a quick e-mail with the corresponding line.
First, an update of the package lists:
xyz@ubuntu:~$ sudo apt-get update
[sudo] password for xyz: 
Ign http://de.archive.ubuntu.com precise InRelease
Ign http://de.archive.ubuntu.com precise-updates InRelease
Ign http://de.archive.ubuntu.com precise-backports InRelease
Ign http://security.ubuntu.com precise-security InRelease
OK   http://de.archive.ubuntu.com precise Release.gpg


OK   http://security.ubuntu.com precise-security/restricted Translation-en
OK   http://security.ubuntu.com precise-security/universe Translation-en
Paketlisten werden gelesen... Fertig


Of course, you can optionally install a SSH server on the system, so you can work on the system via SSH instead of on the console::
xyz@ubuntu:~$ sudo apt-get install openssh-server
And now the installation of the packages required for the installation of RVM and later Ruby on Rails:
xyz@ubuntu:~$ sudo apt-get install curl git-core patch \
   build-essential bison zlib1g-dev libssl-dev libxml2-dev \
   libxml2-dev sqlite3 libsqlite3-dev autotools-dev \
   libxslt1-dev libyaml-0-2 autoconf automake libreadline6-dev \
   libyaml-dev libtool
Paketlisten werden gelesen... Fertig
Abhängigkeitsbaum wird aufgebaut       
Statusinformationen werden eingelesen... Fertig


g++ (4:4.6.3-1ubuntu5) wird eingerichtet ...
update-alternatives: /usr/bin/g++ wird verwendet, um /usr/bin/c++ (c++) im Auto-Modus bereitzustellen.
build-essential (11.5ubuntu2) wird eingerichtet ...
Trigger für libc-bin werden verarbeitet ...
ldconfig deferred processing now taking place

Installing Ruby 1.9.3 with RVM

RVM can be installed in various ways. I recommend using the following monster command (please copy it exactly) that installs the latest RVM:
xyz@ubuntu:~$ curl -L https://get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   185  100   185    0     0    336      0 --:--:-- --:--:-- --:--:--  1016
100  8545  100  8545    0     0   6895      0  0:00:01  0:00:01 --:--:--  6895
Downloading RVM from wayneeseguin branch stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   125  100   125    0     0    192      0 --:--:-- --:--:-- --:--:--   262
100  994k  100  994k    0     0   248k      0  0:00:04  0:00:04 --:--:--  362k

Installing RVM to /home/xyz/.rvm/
    Adding rvm PATH line to /home/xyz/.bashrc /home/xyz/.zshrc.
    Adding rvm loading line to /home/xyz/.bash_login /home/xyz/.zlogin.

# RVM:  Shell scripts enabling management of multiple ruby environments.
# RTFM: https://rvm.io/
# HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net)
# Cheatsheet: http://cheat.errtheblog.com/s/rvm/
# Screencast: http://screencasts.org/episodes/how-to-use-rvm

# In case of any issues read output of 'rvm requirements' and/or 'rvm notes'

Installation of RVM in /home/xyz/.rvm/ is almost complete:

  * To start using RVM you need to run `source /home/xyz/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.

# xyz,
#   Thank you for using RVM!
#   I sincerely hope that RVM helps to make your life easier and more enjoyable!!!
# ~Wayne

rvm 1.12.5 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

RVM is now fully installed. You now either need to close your terminal and therefore your shell and then restart it, or load the rvm script as follows:
xyz@ubuntu:~$ source ~/.rvm/scripts/rvm
To test if rvm is correctly installed, let's try calling it with -v:
xyz@ubuntu:~$ rvm -v

rvm 1.12.5 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

If you should get the bash command not found as reply, you need to check the above steps again.
The following command displays the rubies (Ruby interpreters) that RVM knows.
xyz@ubuntu:~$ rvm list known
# MRI Rubies




There are different interpreters for Ruby. The relevant one for us is the normal MRI (Matz's Ruby Interpreter) [10], whose core is the Ruby VM with the name YARV (Yet Another Ruby VM) [11] as of Ruby 1.9.
Now you can use RVM to install Ruby 1.9.3:
xyz@ubuntu:~$ rvm install 1.9.3
Fetching yaml-0.1.4.tar.gz to /home/xyz/.rvm/archives
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  460k  100  460k    0     0   148k      0  0:00:03  0:00:03 --:--:--  170k
Extracting yaml-0.1.4.tar.gz to /home/xyz/.rvm/src
Prepare yaml in /home/xyz/.rvm/src/yaml-0.1.4.
Configuring yaml in /home/xyz/.rvm/src/yaml-0.1.4.


ruby-1.9.3-p194 - adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.3-p194 - #importing default gemsets (/home/xyz/.rvm/gemsets/)
Install of ruby-1.9.3-p194 - #complete 
By default, RVM immediately offers the Ruby version you have just installed:
xyz@ubuntu:~$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]


If you have previously installed a system version of Ruby 1.8.x, you can switch back to this version any time via the command rvm system.


You can enter the command rvm to display a corresponding help page with further available commands.

Generate Ruby Documentation

Ruby has an integrated and constantly available documentation (see the section called “Help via ri”). If you want to install this (and I highly recommend you do), you now need to start rvm docs generate:
MacBook:~ xyz$ rvm docs generate

Installing Rails

First, we check if Ruby is called in version 1.9.3. If this is not the case, please read the section called “Installing Ruby 1.9.3 with RVM”.
xyz@ubuntu:~$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]
Then we make sure that the gem package management is up to date:
xyz@ubuntu:~$ gem update
Updating installed gems
Nothing to update

Installing Rails 3.2

The rest is easy:
xyz@ubuntu:~$ gem install rails --version '~> 3.2.0'
Fetching: i18n-0.6.0.gem (100%)
Fetching: multi_json-1.3.2.gem (100%)


Installing RDoc documentation for railties-3.2.7...
Installing RDoc documentation for rails-3.2.7...
Perfect. You have now installed Rails 3.2.
xyz@ubuntu:~$ rails -v
Rails 3.2.7


If you want to install an older Rails version one day, you can edit the parameter --version by inserting the corresponding older version number (for example --version '-> 3.1.0' for the most current Rails 3.1 version).

And Now?

If you have never worked with Ruby before, you should first read Chapter 2, Ruby Basics. If you are already a Ruby master and want to move on to Rails now, then I recommend reading Chapter 3, First Steps with Rails.

Updates about this book will be published on my Twitter feed.