Install Ruby and Ruby On Rails on Ubuntu    July 2, 2006    8

Recently I started messing around with Ruby and I wanted to set it up on our local server, so I gave InstantRails a go – and it worked perfectly.

Meanwhile we changed our operating system and switched from Windows to Linux (Ubuntu Dapper), so now I needed Rails for Ubuntu. Unfortunately (or luckily) there is no InstantRails for Ubuntu. The only way to go was to install “real” Ruby and Rails, so I had to figure out how to install it once again.

Again I tried to find a meaningful and complete tutorial, but I didn’t found it so I had to glue pieces from different sources (you have a complete list of articles I used at the end). I wanted to do this as simple as possible and without any compiling.

Install Ruby and Ruby On Rails packages

There are quite a few packages you need to install and the easiest way to do that is to use Synaptic package manager, but if you prefer you can use apt-get or anything else you fancy. Before you continue make sure that you have enabled Universe repository (how to add repositories), otherwise some of the packages might not show up.

You need to install following packages as well as all dependencies for them (Synaptic will let you know if some package needs additional packages):

  • ruby1.8 – installs Ruby 1.8.4
  • libmysql-ruby – additional libraries to access MySQL
  • libopenssl-ruby – adds SSL capability to Ruby
  • libruby1.8-dbg – debugging library
  • ri – Ruby Interactive Reference
  • ruby1.8-dev – header files for building extensions
  • rails – Ruby On Rails framework

When you install all of those you should be able to go to terminal and check if Ruby is properly installed. Just type ruby -v and you should see something like this:

basti@Bali:~$ ruby -v
ruby 1.8.4 (2005-12-24) [x86_64-linux]

You can also try a simple command line program like:

ruby -e 'print "hello world\n"'


Next you would need RubyGems which is kind of package manager for Ruby. You will need it to get additional (3rd party) Ruby scripts such as Rails. There is no Ubuntu package for RubyGems so you have to install it manually.

You need to download latest version of RubyGems from RubyForge and unpack it anywhere you like. Then in terminal go to that dir and type:

sudo ruby setup.rb
sudo gem install rubygems-update
sudo gem install rails --include-dependencies

This will install RubyGems, update it, install rails and all required gems/packages (just answer to all dependency questions with yes).

Testing Rails by building lame Hello World app

To create a sample Ruby app you need to type following to terminal (providing that you are in a dir where you want to place hello app):

rails ./hello
cd hello
ruby script/server

This will create a new application in hello dir and will start Webrick server (development web server for Ruby). Now if you go to you should see Rails welcome page.

The final test is to create a proper Hello World app, that is you need to generate a ‘hello’ controller. You can do that by going to hello dir and typing:

ruby script/generate controller hello

and then editing file hello/app/controllers/hello_controller.rb to look like this:

class HelloController < ApplicationController
   def index
      render_text "Lame Hello World"

Finally, start Webrick once again (type: ruby script/server) and point your browser to and that’s it.

What’s next?

This setup isn’t perfect, but for a single developer it would do just fine. My next task is to configure Webrick a bit more (for example, make it available for other people in my network to access it) or to make Rails work through my existing Apache (although it seems that it isn’t suitable for development as it caches Ruby pages).

You may also be interested to look at these:

Ruby, Rails, Apache2, and Ubuntu Breezy (5.10)
Official Rails site with “short” 37signals-style install guide


Sanjiv Kumar Jha July 11th, 2011 at 7:50 am

I have ran rake db:create (database is mysql).But it give me following error;

rake aborted!
/home/sanjiv/app1/Rakefile:5: Invalid char `\342′ in expression
/home/sanjiv/app1/Rakefile:5: Invalid char `\200′ in expression

Please help me out .i am new ruby programmer

Rakesh Suryavardhan April 8th, 2010 at 12:11 pm

Thanks for the tutorial. Im a newbie to Ruby. Im able to install it run the server and all, but when I ran the hello controller it returned error. undefined method ‘render_text’. What will be the problem??

Vikas Hazrati January 13th, 2007 at 3:50 pm

OK understood the posting screw up the single quotes and double quotes. Sorry :)

Vikas Hazrati January 13th, 2007 at 3:49 pm

wonderful i wanted to know how to test ruby on linux and i got it here, though copy paste of the single line program gave me
~$ ruby -e ‘print “hello world\n”‘
-e:1: Invalid char `\342′ in expression
-e:1: Invalid char `\200′ in expression
-e:1: Invalid char `\230′ in expression

the correct one should be
ruby -e ‘print “hello world\n”‘

Matt September 21st, 2006 at 5:01 pm

thanks! Finally I got RoR on Ubuntu!

uaretroublesome August 25th, 2006 at 8:45 am

thanks for the short and sweet tips

Add a Comment