Tuesday, July 5, 2011

Installing Ruby 1.9.2 on Ubuntu (11.04) as its Default Ruby without RVM

I have recently upgraded my Ubuntu to 11.04 with a clean install. So I had to reinstall Ruby all over again. This time I wanted to install Ruby 1.9.x instead of 1.8.7 as its default (system) Ruby.

RVM (Ruby Version Manager) is a recommended tool to install Ruby, but I think I have to have a Ruby installed already before even installing RVM, which is a Ruby gem. This is my initial (pre-RVM) Ruby installation.

Besides, I do not know yet a simple way to use an RVM-installed Ruby when I want to run it without logging in and without launching bash shell - running as a daemon. So I really wanted to install 1.9.x version of Ruby as my default (system) Ruby.

Ubuntu has two versions of Ruby in its repository: 1.8.7 and 1.9.1. So I installed 1.9.1 using Synaptic. To my surprise, it installed 1.9.2!.

$ ruby1.9.1 -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
Now I do not like to call ruby like
$ ruby1.9.1 myapp.rb
So I just created a symlink.
$ sudo ln -s /usr/bin/ruby1.9.1 /usr/bin/ruby
$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]

I did the same thing for gem1.9.1 and irb1.9.1.
$ sudo ln -s /usr/bin/gem1.9.1 /usr/bin/gem 
$ sudo ln -s /usr/bin/irb1.9.1 /usr/bin/irb
$ gem -v
$ irb -v
irb 0.9.6(09/06/30)
$ irb
irb(main):001:0> RUBY_VERSION
=> "1.9.2"

[New] Finally, I added /var/lib/gems/1.9.1/bin to the PATH so that gems can be accessible as commands. I added the following line at the end of my .bashrc.
export PATH=/var/lib/gems/1.9.1/bin:$PATH

I have now the latest Ruby and irb as my default (system) Ruby in the latest Ubuntu.


  1. Thanks, this helped a lot. Believe I found one problem though -- the line for creating the symlink to ruby1.9.1 should read:

    sudo ln -s /usr/bin/ruby1.9.1 /usr/bin/ruby

  2. Driklyn,
    Thank you. I have corrected the error.

  3. Thanks, that was helpful.

  4. Thanks, I first used the alias command but this is better :)

  5. I found that in ubuntu 11, usr/bin/ruby points to the /etc/alternatives/ruby.

    ls -l /usr/src/rub* will show a preexisting symbolic link initially:

    ruet@Rails-Server:~$ ls -l /usr/bin/rub*
    lrwxrwxrwx 1 root root 22 2011-12-28 12:25 /usr/bin/ruby -> /etc/alternatives/ruby
    -rwxr-xr-x 1 root root 5504 2011-07-27 06:32 /usr/bin/ruby1.8
    -rwxr-xr-x 1 root root 5516 2011-07-27 16:24 /usr/bin/ruby1.9.1

    In the spirit of debian style alternatives, I suggest using this command instead, with a -f to ensure it is overwritten.

    sudo ln -s -f /usr/bin/ruby1.9.1 /etc/alternatives/ruby