In this tutorial I’ll explain How to Set Up Ruby and Rails on Ubuntu. It can can be attempted in a couple of ways. I have tried them all at one time or another, and generally always ran into problems. So I decided to try compiling everything to see how that worked. I can report that it worked, with a few hoops to jump through.
The stable version of Ruby has moved up to version 1.9.3, and Rails is currently at version 3.1.1 at the time of writing. Getting everything set up to work on Ubuntu involves some compiling from source, and some trouble shooting, but it is possible. I explain how I got it working below.
How to Set Up Ruby and Rails on Ubuntu – Step 1
The first thing to be aware of is this:
Ruby 1.9.3-p0 uses psych; it is the replacement for version 1.8.7’s YAML library called Syck, the default YAML parser. Psych is a wrapper around libyaml, a library file that Ubuntu does have in it’s repositories. However, DO NOT install the one available in the package manager, it won’t work with Ruby 1.9.3.
You also have to have libyaml installed, otherwise Ruby will not compile correctly. So lets install it from source, open terminal and cd into your Downloads directory:
#get the source wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz #untar the file tar xzvf yaml-0.1.4.tar.gz #move into the directory cd yaml-0.1.4 #compile ./configure --prefix=/usr/local make sudo make install
Adding other libraries
Now that we have libyaml sorted, we also need some other libraries for Ruby. You can safely use the package manager to install these: zlib1g, zlib1g-dev, build-essential, openssl, libssl-dev, libmysqlclient16-dev. I discovered that these files were required for Ruby 1.9.2, so it seems likely that 1.9.3 needs them too.

Installing Ruby
Right, now we can install Ruby. Back on the command line:
#download the Ruby source wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz #untar the file tar xzvf ruby-1.9.3-p0.tar.gz #move into the source directory cd ruby-1.9.3-p0 #configure with options to avoid errors ./configure --prefix=/usr/local --enable-shared --disable-install-doc --with-opt-dir=/usr/local/lib # compile make sudo make install
I tried just a regular ./configure and noticed quite a few errors, so after extensive research, the options shown seemed the most likely to work. The installation will then run through for a while. Once it finishes, you can try:
ruby -v
And it should report that you have ruby 1.9.3p0. Also, while we are at it, lets check the version of Ruby gems:
gem -v
you should get a response that says: 1.8.11.
Installing Rails
On the command line type:
sudo gem install rails
This will take a while, but should complete successfully. Once the process finishes, we can then try out a test project. I tend to create a folder in my home folder called ‘rails_projects’:
cd ~/ mkdir rails_projects rails new testing
This will look like it is going to run through fine, but will then possibly fail if the sqlite3 headers are not installed. We can install them like so:
sudo apt-get install libsqlite3-dev
Then create your project again. This time it should run through successfully. We are not in the clear yet though. When you cd into the project folder and run the built-in Rails web server:
rails s
you will possibly get a screen full of errors. Scroll back to the top, and you find that Rails is complaining about the lack of a Javascript runtime engine. We can fix that by opening up the gem file and adding: gem ‘therubyracer’ to it. Run bundle install again, and then start the server again. This time it should work:

Rails Server
Open your browser and go to http://localhost:3000. You’ll be greeted by the default Rails welcome page.
Wrap Up
So there we have it, a complete installation of Ruby 1.9.3 and Rails 3.1.1 on Ubuntu 11.10.It seemed like a lot of effort, but it works, and it’s nice to know that I now have some idea of how to get Ruby and Rails working on Ubuntu.
Tags: installing, Rails, ruby 1.9.3, Ubuntu