Install Ruby and Ruby On Rails on Ubuntu

Posted By Slobodan Kovacevic on July 2, 2006

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”‘

RubyGems

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 http://0.0.0.0:3000 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"
end
end

Finally, start Webrick once again (type: ruby script/server) and point your browser to http://0.0.0.0:3000/hello 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

About the author

Slobodan Kovacevic

Comments

6 Responses to “Install Ruby and Ruby On Rails on Ubuntu”

  1. thanks for the short and sweet tips

  2. Matt says:

    thanks! Finally I got RoR on Ubuntu!

  3. [...] Ruby on Rails. Install on Ubuntu. [...]

  4. Vikas Hazrati says:

    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”‘

  5. Vikas Hazrati says:

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

Add a Comment

\n\n -->