1.5. Debian 6.0 (Squeeze) - 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 Debian GNU/Linux 6.0 (Squeeze). You can find an ISO image for the installation at http://www.debian.org/releases/squeeze/debian-installer/. I recommend the net installation CD image, about 160 MByte. You will find a Debian GNU/Linux installation instruction at http://www.debian.org/releases/squeeze/i386/


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 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 lines.
First, an update of the package lists:
root@debian:~# aptitude update
Treffer http://ftp.de.debian.org squeeze Release.gpg                            
Hole:1 http://ftp.de.debian.org/debian/ squeeze/main Translation-de [1.514 kB]
Hole:2 http://security.debian.org squeeze/updates Release.gpg [836 B]


1820kB wurden in 12s heruntergeladen (150kB/s)
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:
root@debian:~# aptitude -y install openssh-server
And now the installation of the packages required for the RVM installation:
root@debian:~# apt-get -y install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion python
Now is a good time to log out as root:
root@debian:~# exit

Installing Ruby 1.9.3 with RVM

Log in with your normal user account (in our case, it's the user xyz).
RVM can be installed in various ways. I recommend using the following monster command (please copy it exactly) that installs the latest RVM:
xyz@debian:~$ 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  8545  100  8545    0     0   2089      0  0:00:04  0:00:04 --:--:-- 13628
Downloading RVM from wayneeseguin branch stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  994k  100  994k    0     0  68488      0  0:00:14  0:00:14 --:--:--  144k

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@debian:~$ source ~/.rvm/scripts/rvm
To test if rvm is correctly installed, let's try calling it with -v:
xyz@debian:~$ 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. [6]:
xyz@debian:~$ rvm list known
# MRI Rubies




There are different interpreters for Ruby. The relevant one for us is the normal MRI (Matz's Ruby Interpreter) [7], whose core is the Ruby VM with the name YARV (Yet Another Ruby VM) [8] as of Ruby 1.9.
Now you can use RVM to install Ruby 1.9.3:
xyz@debian:~$ 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  42775      0  0:00:11  0:00:11 --:--:-- 85978
Extracting yaml-0.1.4.tar.gz to /home/xyz/.rvm/src
Configuring yaml in /home/xyz/.rvm/src/yaml-0.1.4.
Compiling yaml in /home/xyz/.rvm/src/yaml-0.1.4. 


Installation of rubygems completed successfully.
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@debian:~$ 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:
xyz@debian:~$ rvm docs generate

Installing Rails

First, we check if Ruby opens in version 1.9.3. If this is not the case, please read the section called “Installing Ruby 1.9.3 with RVM”.
xyz@debian:~$ 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@debian:~$ gem update
Updating installed gems
Nothing to update

Installing Rails 3.2

The rest is easy:
xyz@debian:~$ 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 rdoc-3.12...
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@debian:~$ 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.