Jan 04 2009
Installing Ruby on Rails on Linux
I bet you Linux people smirked when the Mac OS X guys had to use the command line (possibly for the first time), didn’t you?
Well, if you’re running Linux, I’ll assume that you’re used to the command line, so I won’t feel bad throwing you an archaic series of commands to install all the software you need to be up and running with Rail.
Using a Package Manager
As I mentioned, many Linux distributions come with their own package managers, including apt-get , yum, and rpm, among others.
Of course, you’re free to use the package manager that’s bundled with your Linux distribution to install Ruby, and if you become stuck with the instructions given here for whatever reason, that may be a good option for you.
Rather than attempt to cover all the different package managers available, I’ll show you how to install Ruby the manual way.
Prerequisites
The only prerequisite for installing Ruby on Linux is that you have the gcccompiler installed on your machine. gcc ships with most Linux distributions by default, but if it’s not on your system, you’ll either need to use your system’s package management system to install it (look for “build essential” or “basic compiler”), or to download a native binary for your system.8
Enter the following instructions at the command line to confirm that your compiler is in place:
$ gcc -v
If the version number for the compiler is displayed, as shown in Figure 2.13, you’re ready to install Ruby.
Installing Ruby on Linux
Ruby is available for download from the Ruby ftp site.9 As mentioned at the outset of this chapter, I recommend the use of version 1.8.6 of the Ruby interpreter.
Build Dependencies
Here is a quick tip if you are using a Debian-based Linux distribution-Ubuntu, for example). Before compiling Ruby, make sure you have all the required packages by entering the following command:
$ apt-get build-dep ruby1.8
Download the appropriate tar file for Ruby (this will be named something like ruby1.8.6.tar.gz), and extract the archive using the gunzip and tar commands:
$ gunzip ruby-1.8.6.tar.gz
$ tar xvf ruby-1.8.6.tar
$ cd ruby-1.8.6
Then change into the new directory that was created, From this directory, run the following command to compile and install Ruby in /usr/local:
$ ./configure && make && sudo make install
This process may take 20 minutes or more, so be patient.
Once it’s completed, you should add /usr/local/bin to your PATHenvironment variable. I’ll assume that, being a Linux user, you know how to do that. Once that environment variable is set, you can enter the following command to check which version of Ruby you installed:
$ ruby -v
The message displayed should confirm that you’re running version 1.8.6
Now, on to the next step: installing RubyGems.
Installing RubyGems on Linux
Next up is the installation of RubyGems, the package manager for Ruby-related software. RubyGems works much like the package manager that your operating system uses to manage the various Linux utilities installed on your machine. RubyGems makes it easy to install all sorts of additional software and extensions for Ruby.
RubyGems is available for download from http://rubyforge.org/projects/rubygems/. Once you’ve downloaded and extracted it, change to the rubygems directory and run the following command:
$ sudo gem update –system
Installing Rails on Linux
Using RubyGems, the installation of Rails itself is a breeze. To install Rails, type the following input at the command prompt as the root user (or using sudo if it’s installed on your system):
$ sudo gem install rails
The process may take ten minutes or so, depending on the speed of your Internet connection, but that’s all you need to do! And as an added bonus, RubyGems gives us an easy way to stay up to date with future Rails releases—whenever we want to upgrade Rails, we just need to type this command!
To confirm that your Rails installation was successful, type the following command to display the version of Rails that was installed:
$ rails -v
All that’s left now is to install a database—then we can get to work!
Installing SQLite on Linux
Most modern Linux distributions may or may not come packaged with a (more or less) recent version of SQLite and you’re free to use that. It is crucial, however, that you’re installing SQLite 3.x (as opposed to SQLite 2.x).
In case your Linux distribution doesn’t ship with a prepackaged version of SQLite, follow the simple installation instructions found below.
SQLite is available for download from http://www.sqlite.org/download.html. The rest of these instructions assume you download the source tarball. As of this writing, the most recent version of SQLite available was 3.5.4.
Once you have the file, it’s time to extract and compile it using the following batch of commands:
$ tar zxvf sqlite-3.5.4.tar.gz
$ cd sqlite-3.5.4
$ ./configure –prefix=/usr/local
$ make
$ sudo make install
At this point you have successfully installed SQLite on your Linux system. To confirm that, the following command will print out the version of SQLite that you downloaded and installed:
sqlite3 –version
Assuming that you have the directory /usr/local/bin in your operating system PATH.
Installing the SQLite Database Interface for Ruby
Lastly, we need to install a tiny little module that allows Ruby to talk to SQLite databases. To do so, we’ll use the RubyGems system we’ve installed earlier. Because of that, the installation boils down to a single command only:
sudo gem install sqlite3-ruby
Congratulations, now you’re all done!
Leave a Reply
You must be logged in to post a comment.
Not A Member? Register for Free!

