My Brain on Code

Ruby on Rails on Ubuntu 9.04 (Jaunty)

I wanted to get started with Ruby on Rails development and while there is a ruby package in the ubuntu repositories, I wanted to compile it from source. I feel more in control that way ;) These are the steps I went through to get up and running with a rails stack.

First, Install prerequisites:

sudo apt-get -y install build-essential libssl-dev libreadline5-dev zlib1g-dev

Downloaded ruby 1.8.7 source:

wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p174.tar.gz

Extract the contents:

tar -xzf ruby-1.8.7-p174.tar.gz

Change directories:

cd ruby-1.8.7-p174

Configure the source:

./configure --prefix=/usr/local/ruby-1.8.7 --with-openssl-dir=/usr/lib \
    --with-readline-dir=/usr/lib --with-zlib-dir=/usr/lib

Run make:

make

Test the Ruby interpreter. This will check whether the compiled Ruby Interpreter works well. If all went well you should see “test succeeded”:

make test

Install ruby:

sudo make install

Make a symlink to ruby:

sudo ln -s /usr/local/ruby-1.8.7/bin/ruby /usr/bin/ruby

Test ruby to make sure its working. You should get a “success” message.

ruby -ropenssl -rzlib -rreadline -e "puts :success"

Download Ruby Gems:

cd /tmp
wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz

Extract:

tar -xzf rubygems-1.3.5.tgz

Change directories:

cd rubygems-1.3.5

Run Setup:

sudo ruby setup.rb

Make a symlink to gems:

sudo ln -s /usr/local/ruby-1.8.7/bin/gem /usr/bin/gem

Install rails:

sudo gem install rails

Make a symlink to rails:

sudo ln -s /usr/local/ruby-1.8.7/bin/rails /usr/bin/rails

Rails is now installed!

We still need to install a few more things. Rails by default uses sqlite as a database backend so make sure it’s installed:

sudo apt-get install sqlite3 libsqlite3-dev

Next we need to install the rake gem:

sudo gem install rake

Create a symlink to rake:

sudo ln -s /usr/local/ruby-1.8.7/bin/rake /usr/bin/rake

Now we need to install the ruby bindings for sqlite3 (NOTE: you may get a few warnings at this step but it still installs and runs fine)

sudo gem install sqlite3-ruby

That should be it! Your RoR stack on Ubuntu should be complete. Code away!