How to Install Ruby on Rails on Ubuntu 9.04 (Jaunty Jackalope)

Rails on Ubuntu

Few of my friends have started to learn Ruby on Rails recently. According to my point of view, Windows is not a suitable and enjoyable  environment for RoR development. So, I recommended them to start with Ubuntu. Most of them have installed Ubuntu 8.10 and 9.04. So, I wish to write a small guide to setup the Ruby on Rails environment on Ubuntu 8.10 and 9.04

If you like to watch the screencast of this title, rather than reading whole post, you can find my screencast here.

Ruby installation

First we need to update the repositories.

sudo apt-get update

It’s always a best practice to upgrade the system.

sudo apt-get dist-upgrade

This installation will take few minutes and also require approximately 100 MB disk space.

Now that we are up to date. Let’s start install the RoR recipices. We need following Rails prerequisites.

ruby = An interpreter of object-oriented scripting language Ruby
ri = Ruby Interactive reference
rdoc = Generate documentation from ruby source files
irb = Interactive Ruby

sudo apt-get install ruby ri rdoc irb libopenssl-ruby ruby-dev

Ruby Gem installation

Next we need to install the Ruby gem package manager. You can download the latest Ruby gems by following link.

http://rubyforge.org/projects/rubygems/

Download and extract the files. (By the time I’m writing this tutorial the latest version is 1.3.1)


tar xvzf  rubygems-1.3.1.tgz
cd rubygems-1.3.1
sudo ruby setup.rb

Once it’s done you can delete the .tgz file and rubygems directory.

cd ..
rm -r rubygems-1.3.1 rubygems-1.3.1.tgz

Next we need to create a set of simlinks. Otherwise it will be a tedious task to type commands with the version (1.8).  For an example if we need to call the gem command we’ve to type gem1.8. I don’t prefer that. Hope you too. So, let’s create the necessary simlinks.


sudo ln -s /usr/bin/gem1.8 /usr/local/bin/gem
sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby
sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc
sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri
sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb

Rails Installation

Now we can install Rails using gem.

sudo gem install rails

Server Installation

Rails by default comes with the WEBrick server. But most Rails developers prefer the Mongrel server. If you satisfied with WEBrick you can skip this step, else type the following command to install Mongrel server.

sudo gem install mongrel

If you got any error while installing the Mongrel server, install the ruby-dev / ruby1.8-dev and try again.

sudo apt-get install ruby-dev

Database Installation

Rails 2.3 shipped with  SQLite3 as it’s default database instead of  MySQL. You can install SQLite3 libraries by following commands.

sudo apt-get install sqlite3 swig libsqlite3-ruby libsqlite3-dev
sudo gem install sqlite3-ruby

If you prefer MySQL,

sudo apt-get install mysql-client libmysqlclient15-dev
sudo gem install mysql

Create Ruby on Rails App

Now that we have completed everything successfully. You can create your new Ruby on Rail applicaion by following command.

rails test_app

If you need MySQL supported applicaion you need to specify as follows

rails test_app -d mysql

Run the app


cd test_app
script/server

navigate you browser to http://localhost:3000

ubu

Wola.. you have done it…!

Happy Rails…!