How to install Ruby on Rails on Linux

This might be the fourth time I have to install RoR in one of my machines and I struggle every time I have to. This post is to make me “not forget” how to install Ruby on Rails on Linux that doesn’t have the latest version of Rails packaged. The following steps have been executed on a 64-bit Debian Lenny machine.

So, the first step is to get the Ruby source code, compile and install. Easy “configure+make+makeinstall” task, starting from its website. The version I downloaded was 1.9.2-p180.

$ wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p180.tar.gz 
$ tar -xzf ruby-1.9.2-p180.tar.gz 
$ cd ruby-1.9.2-p180 
$ RUBYDIR="/opt/ruby-1.9.2" 
$ ./configure --prefix="${RUBYDIR}" 
... 

Ah! There is one additional step: you might also add some modules to the compilation, like “readline” and/or “openssl” (Heroku needs it) and for that you need to uncomment those lines in the “ext/Setup” file. After editing (or not) you can continue with:

$ make 
... 
$ sudo install -d -o `id -u` "${RUBYDIR}" 
$ make install 
... 

Set your PATH to include the Ruby binary directory (you might also set it in the “/etc/profile” file):

$ PATH="${RUBYDIR}/bin:${PATH}"

Some applications ask for specific modules like “readline” (Heroku needs it). For that you need to install it calling:

$ cd ext/readline 
$ ruby extconf.rb 
... 

If you don’t see “creating Makefile” at the end of the log messages, the building won’t work. Install the needed packages (with “apt-get install libreadline5-dev”, for example) and re-run it. After that just “make+makeinstall”:

$ make 
... 
$ make install 
... 

Now let’s install Rails:

$ gem install rails 
... 

You might also want to install some additional packages too, like “jquery-rails” and “heroku”:

$ gem install jquery-rails heroku 
... 

Finally, fix the Ruby directory permissions:

# sudo chown -R root:root "${RUBYDIR}"