Installing Ruby 1.9.2 and Rails 3 stable on Ubuntu

Let’s install Ruby 1.9.2 and Rails 3 stable on Ubuntu. I’m going to use just one Ruby version so, this installation without RVM (Ruby Version Manager). I’m using Ubuntu 10.04, 32 bit version.

If you have not yet installed the following packages - install them:

$ sudo apt-get install gcc g++ build-essential libssl-dev libreadline5-dev zlib1g-dev linux-headers-generic libsqlite3-dev

Now download Ruby 1.9.2 sources, unpack them and install:

$ wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz
$ tar -xvzf ruby-1.9.2-p0.tar.gz
$ cd ruby-1.9.2-p0/
$ ./configure --prefix=/usr/local/ruby
$ make && sudo make install

Add path to binary Ruby files.

$ sudo gedit /etc/environment

You need to add in the PATH variable that path - /usr/local/ruby/bin, should look something like this:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ruby/bin"

Then run the source command for the file /etc/environment to apply changes.

$ source /etc/environment

Now check is Ruby installed properly:

$ ruby -v

You should see something like this: ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
Now create a symbolic link for ruby and gem program

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

Ruby 1.9.2 is already includes Rubygems, so you do not have to install it.
Now install the required gem packages, including Rails 3.:

$ sudo gem install tzinfo builder memcache-client rack rack-test erubis mail text-format bundler thor i18n sqlite3-ruby
$ sudo gem install rack-mount --version=0.4.0
$ sudo gem install rails --version 3.0.0

Check Rails version:

$ rails -v

You should see the version number 3.0.0. Otherwise, try to execute command source /etc/environment and enter rails -v command once again.
Now you are ready to create a new Rails 3 application:

$ rails new myproject
cd myproject
rails server

UP: To update rails to latest version (3.0.3 for now), run:

sudo gem update rails

And change rails gem in your Gemfile to gem ‘rails’, ‘3.0.3′

Also interesting

Tags: , , ,

33 Responses to “Installing Ruby 1.9.2 and Rails 3 stable on Ubuntu”

  1. John says:

    Great write up! I’m going to give this a shot on Ubuntu 10.04 64-bit.

    Thanks!

  2. Artem says:

    why not checkinstall instead of “make install”? http://goo.gl/pB8W

  3. John says:

    The directions worked great! I was able to get it up and running on 10.04 64-bit with only one hiccup. I previously had Ruby 1.8 installed with Rails 2.3.8. I removed them, but the file /usr/bin/rails pointed explicitly to /usr/bin/ruby1.8. I just pointed that to the symlink made in this write up and it worked like a champ!

    I use PostgreSQL so I added support for that.

    Here is what I did if it helps anyone.

    For Ubuntu 10.04 LTS

    $ sudo apt-get install postgresql postgresql-client postgresql-contrib libpq-dev
    $ sudo gem install pg

    Thanks again for the great write up.
    John

  4. Ouch! says:

    I also installed Ruby 1.9.2, previously deleted the old version 1.8.7. But if someone wants to use both version of Ruby (you can switch between them), use RVM (Ruby Version Manager).

    John, thx for your comment.

  5. ravi says:

    thanks for this wonderful post.
    yes, i too preferred to use RVM which allows you to switch between different version of rubies and gemsets.

  6. BJ says:

    Thanks for sharing this. I had a fresh copy of Ubuntu installed and everything else I tried resulted in an error.

  7. Athir says:

    if you install build-essentials, I don’t believe you need to also include g++ or gcc as build-essentials includes these. see http://packages.ubuntu.com/lucid/devel/build-essential

  8. Necromant2005 says:

    Thanks,
    But for installing on the clear system and before you be able to run rails server , you have to install sqlite
    # sudo apt-get install libsqlite3-dev
    # bundle install

    ubuntu 10.10 beta

  9. cmud666 says:

    Super!! Great step by step howto ;) Thanx

  10. marko says:

    bravo!

  11. r4ito says:

    Great! It couldn’t have been easier, thanks a lot.

  12. Ce BEE says:

    Thanks a lot, great write up on Rails. A+++

  13. xorgnak says:

    I don’t know about anyone else, but unless I typed “source /etc/environment” in every time I wanted to used irb/ruby/gem/anything in my /usr/local/ruby install. I just put “source /etc/environment” in my .bashrc file, and problem solved.

  14. ruvan says:

    finally i was able to install ruby/ rails on ubuntu thanks to this, was struggling to get ruby1.9 working on 10.10

  15. Said says:

    hello everybody, i followed every your step, rails installed successfully, but when I try to check the rails version I’ve got this error:

    /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:238:in `activate’: can’t activate i18n (~> 0.5.0, runtime) for ["mail-2.2.11", "actionmailer-3.0.0", "rails-3.0.0"], already activated i18n-0.4.2 for ["activemodel-3.0.0", "actionpack-3.0.0", "rails-3.0.0"] (Gem::LoadError)
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:254:in `block in activate’
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:253:in `each’
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:253:in `activate’
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:254:in `block in activate’
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:253:in `each’
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:253:in `activate’
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:254:in `block in activate’
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:253:in `each’
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:253:in `activate’
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:1065:in `gem’
    from /usr/local/ruby/bin/rails:18:in `’

    any suggestion ????

  16. Bijan says:

    Any way to avoid having to retype source env/environment without putting it in the bashrc?

    This wasn’t a problem on ubuntu, but is on Arch.

    Thanks for any help.

  17. Bob A. Booeiy says:

    Thank you SO much! I wanted to avoid RVM because it is a nightmare. It constantly deletes stuff so there is no way I would use it on a production machine. Anyone else that does is asking for misery. Their latest bug was they deleted the entire Ruby directory. I’ve had it completely destroy whole installations doing nothing more than installing a gem.

    Thanks again for the RVM’less install. Anyone that says you should use RVM clearly hasn’t used it for long or has drunken the flavor-aid. RVM is HORRIBLE!

  18. Mark says:

    Great guide. I configured ruby following this. Thanks. :D

  19. Enrique Tron says:

    Excelent!! thanks a lot, congrats

  20. Esteban says:

    very useful!!
    thanks!

  21. mon says:

    It very useful for me.

    Thank you!!!

  22. Jeff Douglas says:

    Awesome!! Thanks!

  23. Adam Gonnerman says:

    This is really strange. I’ve gone through all the steps, everything LOOKS successful but then when I do ruby -v is says it isn’t installed. I tried RVM before this and couldn’t get it going either.

    • Ouch! says:

      Hmm. Try “source /etc/environment” again and also try to close console session then open again and type “ruby -v”

  24. Marcell says:

    Thank you! Worked like a charm

  25. MANIKYALARAO says:

    THANK U|GREAT POST THESE STEPS ARE WORKED FOR ME TO INSTALL ROR IN MY LINUX BOX.

  26. balopat says:

    cheers, it worked for me too, on ubuntu x64 11.04

  27. Pedro says:

    I’m having the same problem as the guy from post #15.

    After rails updates the following error started:

    /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:238:in `activate’: can’t activate rack (~> 1.3.5, runtime) for ["actionpack-3.1.3", "rails-3.1.3"], already activated rack-1.4.0 for ["rack-cache-1.1", "actionpack-3.1.3", "rails-3.1.3"] (Gem::LoadError)
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:254:in `block in activate’
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:253:in `each’
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:253:in `activate’
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:254:in `block in activate’
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:253:in `each’
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:253:in `activate’
    from /usr/local/ruby/lib/ruby/1.9.1/rubygems.rb:1065:in `gem’
    from /usr/local/ruby/bin/rails:18:in `’

Leave a Reply