Installing Ruby on Rails on Ubuntu

This guide is valid for the following distributions:

Ruby on Rails

While there is a nice tutorial in the Ruby on Rails wiki, it’s by no means complete. According to it, you should only type: apt-get install rails to have the newest Rails installed on Ubuntu. It installs both Ruby and Rails, but what about rubygems? Sorry, not this time. There is also another caveat. Although commands like rails test and ruby script/server are working properly, ruby/console is not. If you had the misfortune of experiencing the aforementioned behavior, then this tutorial is just for you.

Pre requirements:

nano /etc/apt/sources.list

Add the following at the end of the file (replace edgy with breezy if you are running Breezy, dapper for Dapper, etc.):

# All Ubuntu repositories
deb edgy main restricted universe multiverse

Update your apt sources:

apt-get update


Install Ruby with developer’s libraries:

apt-get install ruby ri rdoc irb ri1.8 ruby1.8-dev libzlib-ruby zlib1g

Download and install Ruby Gems (no .deb package, unfortunately):

tar xfvz rubygems-0.9.2.tgz
cd rubygems-0.9.2
ruby setup.rb

Update your RubyGems (also updates the gems cache):

gem update --system

If you get Could not find rubygems-update (> 0) in the repository or a similar error, you need to delete your RubyGems cache:

$ gem env gemdir


rm $HOME/.gem/source_cache

In the next step install the OpenSSL bindings for Ruby (needed to install signed gems). They are required if you get the following error: SSL is not installed on this system, while installing signed gems like rake:

apt-get install libopenssl-ruby

And the last one:

gem install rails -y

And this is basically it. There are, however, depending on your needs, some…

Additional steps:

One of them is setting up the Rails to connect to the MySQL database in a proper way. We will be using the MySQL C bindings, which, for one, support the MySQL old style passwords (which is set as default for Ubuntu 5.04), but are also significantly faster (in the 2-3x range) than the native Ruby MySQL bindings. First, we will need to install the gcc compiler (and libc6-dev if you don’t have it already installed). Although strange it may seem, as a default it is not installed on a clean Ubuntu installation.

apt-get install gcc libc6-dev

MySQL development libraries are also required (mysql_config plus mysql/include):

apt-get install libmysqlclient14-dev

(for MySQL 5.0 you might be better of with libmysqlclient15-dev).

And now we can install C MySQL bindings:

gem install mysql

If you get "sh: make: not found" do:

apt-get install make

or if you have it already installed, add it to your path:

export PATH=/usr/bin:"${PATH}"

And, of course, in the end install Mongrel:

gem install mongrel -y

And that’s it. Rails installation is complete. Complicated? Not really :) Happy coding!

75 Responses to “Installing Ruby on Rails on Ubuntu”

  1. abhilash says:

    Paul, when I running command ‘ruby setup.rb’ I got it as

    [root@abhilash rubygems-0.9.2]# ruby setup.rb
    —> bin
    —> lib/rbconfig
    —> lib/rbconfig
    mkdir -p /usr/local/bin/
    install gem /usr/local/bin/
    install gem_mirror /usr/local/bin/
    install gem_server /usr/local/bin/
    install gemlock /usr/local/bin/
    install gemri /usr/local/bin/
    install gemwhich /usr/local/bin/
    install index_gem_repository.rb /usr/local/bin/
    install update_rubygems /usr/local/bin/
    mkdir -p /usr/local/lib/ruby/site_ruby/1.8/
    install gemconfigure.rb /usr/local/lib/ruby/site_ruby/1.8/
    install rubygems.rb /usr/local/lib/ruby/site_ruby/1.8/
    install ubygems.rb /usr/local/lib/ruby/site_ruby/1.8/
    —> lib/rbconfig
    mkdir -p /usr/local/lib/ruby/site_ruby/1.8/rbconfig
    install datadir.rb /usr/local/lib/ruby/site_ruby/1.8/rbconfig
    mkdir -p /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install builder.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install cmd_manager.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install command.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install config_file.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install custom_require.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install dependency_list.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install doc_manager.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install format.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install gem_commands.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install gem_open_uri.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install gem_openssl.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install gem_runner.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install installer.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install old_format.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install open-uri.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install package.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install remote_fetcher.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install remote_installer.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install rubygems_version.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install security.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install server.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install source_index.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install source_info_cache.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install source_info_cache_entry.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install specification.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install timer.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install user_interaction.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install validator.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    install version.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
    0) in any repository

    Pls give a solution to install ruby on rails in redhat linux.

  2. RedHat? Uhm, I’d rather google it. I stay away as far as possible from anything rpm related .) Now as for the error it just might be that the Ruby gems repository was down. Or it may be something completely different.

  3. prijesh says:

    Paul , I hav installed Ruby on Rails using command gem install -y rails in ubuntu.
    After that what wil I do?
    How can I run Ruby on Rails.

    Pls give the procedure to run ruby.

  4. prijesh -> Uhm, have you actually read the guide above? It’s plain and simple, you just need to follow each step carefully.

  5. prijesh says:

    Paul , actually I want to install ‘ postgresql ‘ and apache2 webserver.

    How can I install & run both postgresql & apache2 webserver.
    Then How can I test Rails & write programs in it?

  6. It is out of the scope of this tutorial. But… for apache2 and postgresql just do apt-get install apache2 postgresql and as for writing Rails applications Rails wiki is a good place to start.

  7. prijesh says:

    Hai Paul.
    Do u know how to change the core Rails validation error messages using plugins?
    Or do u know any site that give me answer in brief ?
    Pls reply me…

  8. Uhm, try google. Check the wiki too.

  9. I’m getting errors trying to ‘apt-get’ some packages on Ubuntu 6.10.

    ‘apt-get install ruby’ worked flawlessly, and I was able to run ‘ruby’.

    Next, when I tried ‘apt-get install ri’, i get the following error:

    The following packages have unmet dependencies:
    ri: Depends: ri1.8 but it is not going to be installed

    And then I tried: ‘apt-get install ri1.8′, and it asks me to get rdoc1.8, which gets me this error:

    The following packages have unmet dependencies:
    rdoc1.8: Depends: ruby1.8 (>= 1.8.4-5ubuntu1.2) but 1.8.4-5ubuntu1 is to be installed
    Depends: irb1.8 (>= 1.8.4-5ubuntu1.2) but it is not going to be installed
    Depends: libruby1.8 (>= 1.8.4-5ubuntu1.2) but 1.8.4-5ubuntu1 is to be installed
    When i tried to get librub1.8, it says it is already installed.

    Something’s wrong with the dependency naming or version naming. Has anybody else encountered this?

  10. [...] it wouldn’t do what I told it to do) and with the help of Paul Goscicki and his article Ruby on Rails on Ubuntu I set up my Rails environment and started coding the demo app from my book. Damn, it’s so [...]

  11. amorfis says:

    There is one more thing. I must install also libc6-dev – for C header files. Make calls gcc, and it needs this files.

  12. amorfis: libc6-dev is usually installed by default at some point (either as a dependency or during OS installation), but I’ll add it to the tutorial. Just in case.

  13. costa says:

    when i try to install mongrel i get:

    Building native extensions. This could take a while…
    Successfully installed mongrel-1.0.1
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’: no such file to load — rdoc/rdoc (LoadError)
    from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
    from /usr/local/lib/site_ruby/1.8/rubygems/doc_manager.rb:71:in `load_rdoc’
    from /usr/local/lib/site_ruby/1.8/rubygems/doc_manager.rb:41:in `generate_ri’
    from /usr/local/lib/site_ruby/1.8/rubygems/gem_commands.rb:302:in `execute’
    from /usr/local/lib/site_ruby/1.8/rubygems/gem_commands.rb:301:in `execute’
    from /usr/local/lib/site_ruby/1.8/rubygems/gem_commands.rb:239:in `execute’
    from /usr/local/lib/site_ruby/1.8/rubygems/command.rb:70:in `invoke’
    from /usr/local/lib/site_ruby/1.8/rubygems/cmd_manager.rb:120:in `process_args’
    from /usr/local/lib/site_ruby/1.8/rubygems/cmd_manager.rb:91:in `run’
    from /usr/local/lib/site_ruby/1.8/rubygems/gem_runner.rb:30:in `run’
    from /usr/bin/gem:23


  14. /usr/local? Sorry, can’t help you. I bet 100:1 that your Ruby installation is just hosed. If you are on ubuntu (somehow I doubt that), just follow my guide and it will work just fine.

  15. Ed Arthur says:

    I’m running Ubuntu 6.10 and have ruby 1.8.4 installed.
    I’ve got rails too and just did “gem update –system” yet I have no “irb” on they system…what’s up with that?


  16. Ed Arthur -> You can either follow my guide or just run apt-get install irb.

  17. Ed Arthur says:

    Right, its the apt-get which fails.

    % sudo apt-get install irb
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Couldn’t find package irb

    I’m more of a command line kind of guy but I’ve been using the (Syanptic Package Manager) GUI mainly to install packages on this Ubuntu system.

    I don’t have the “Community maintained Ope Source software or Software restricted by copyright or legal issues boxes checked.


  18. Ed Arhur -> You need to have universe repositories enabled. Edit your /etc/apt/sources.list to include this line:

    deb edgy main restricted universe multiverse

    I’ve updated the guide to reflect this.

  19. Ed Arthur says:

    That did it thanks.

  20. [...] 11th, 2007 Handy tutorial by Paul Goscicki to get Ruby on Rails installed on Ubuntu. It doesn’t cover installation of MySql or Apache (installed already on my [...]

  21. VJ says:

    Than you so much for this tutorial after hours of unsuccessfully trying to set-up ruby on rails on feisty fawn. I finally managed to do it thanks to this tutorial.

  22. Olin says:

    Thanks for a great tutorial. Working ~ Feisty Fawn

  23. Thank you so much for a very simple easy-to-follow tutorial on setting up Rails on Ubuntu.

    I have been so tired of using Windows XP that this weekend I managed to setup a dual boot system with my current Windows XP install and my new favorite operating system Ubuntu.

    I used this great tutorial =>

    to get my dual boot system up and running and then I used your tutorial here to get my ROR up and running.

    Everything worked according to plan and today I am back coding in Ruby on Rails in my Linux environment.

    Thanks a bunch! You saved me tons of time.

    For the rest of you…

    If you are still using Windows, I suggest you take a look at Ubuntu it is fairly easy to install if you can follow directions.
    You won’t be disapointed with this OS and hos much faster and friendlier it is to use.


  24. Vasil Vangelovski says:

    Works like a charm. It seems that that gem update –system command can make a problem if you forget to execute as super user.
    These are the most useful instructions that work on XUbuntu dapper.

  25. Bruno Moura says:

    First I apologize my poor English.

    After to install the ruby 1.8.7 patch level 22 from the source
    on ubuntu 8.04 hardy succefully.

    Then I tryed to install rubygems 1.2 in sequence and I
    received this error message:

    xyz@xyz: /usr/local/src/rubygems-1.2.0$ sudo ruby setup.rb
    /lib/rubygems/spec_fetcher.rb:1:in `require’: no such file to load –
    zlib (LoadError)

    So I tried install zlib1g and zlib1g-dev and after this the problem has not fixed

    And I didn’t unistall ruby for reinstall and recompile…

    I tried many kind of commands like for uninstall and re-compile ruby:

    sudo apt-get remove ruby libruby libruby1.8 ruby1.8 irb rdoc ri
    sudo aptitude remove ruby
    sudo dpkg –list | grep ruby, dpkg -r
    and through Synaptic too

    And when I invoke ruby -v or irb, these commands works normally…

    How Can I fix this problem?

    Thank’s so much for help me!


Leave a Reply