Wednesday, April 30, 2014

Restoring Ruby 2.0 on Ubuntu 14.04

For some reason, Ubuntu 14.04 sets up MRI 1.9.1 as the default Ruby (/usr/bin/ruby and friends) version, even if Ruby was installed using the ruby2.0 package. This post outlines a quick and dirty method for restoring Ruby 2.0 as the default Ruby version.

Method

Issue the following commands in a shell.

sudo rm /usr/bin/ruby /usr/bin/gem /usr/bin/irb /usr/bin/rdoc /usr/bin/erb
sudo ln -s /usr/bin/ruby2.0 /usr/bin/ruby
sudo ln -s /usr/bin/gem2.0 /usr/bin/gem
sudo ln -s /usr/bin/irb2.0 /usr/bin/irb
sudo ln -s /usr/bin/rdoc2.0 /usr/bin/rdoc

sudo ln -s /usr/bin/erb2.0 /usr/bin/erb
sudo gem update --system
sudo gem pristine --all

Discussion

The underlying issue is that the ruby2.0 package in Ubuntu 14.04 depends on the ruby package, which sets up Ruby 1.9.1. The ruby package file list shows that it contains the /usr/bin symlinks used to run ruby and manual pages. The fact that the files are architecture-independent is a pretty good hint that they're not binaries, and merely point to other files. The ruby2.0 package file list (for amd64) shows the binaries that the symlinks need to point to for Ruby 2.0 to become the default version on the system.

The commands above restore the symlinks in the ruby package and rebuild all the gems, to ensure that their /usr/bin stubs are set up correctly as well. Regenerating the gems is a good idea after a system upgrade anyway, because this causes extensions to be re-compiled against the updated libraries. 

Conclusion

The ruby packaging in Ubuntu 14.04 has a nasty surprise for upgraders who use ruby2.0 as the default Ruby interpreter. This post provides a quick workaround for the problem. I hope you found this useful, and look forward to your comments and feedback!