PPA Updates for Ruby 1.9.1 and Ruby 1.9.2 – Handling Ruby Versions using the update-alternatives system

I recently created PPAs for Ruby 1.9.1 and Ruby 1.9.2. The default Ruby 1.9.1 package creates binaries in /usr/bin with names like ruby1.9.1, irb1.9.1 etc. However a lot of scripts depend on /usr/bin/ruby and /usr/bin/irb which are provided by Ruby1.8. Hence when I created the PPA for ruby1.9.1, I hardcoded the symlinks – /usr/bin/ruby1.9.2 => /usr/bin/ruby etc.

However Antonio suggested that I should use the update-alternatives system instead. I knew that was the way to go, but didn’t read up about it when I was creating the PPAs and used the symlinks instead. I took his suggestion and updated the Ruby1.9.1 and Ruby1.9.2 packages to support the update-alternatives system. However I soon realized that the Ruby1.8 package still uses hard-coded symlinks. So I ended up updating the Ruby-Defaults package too so that Ruby1.8 would support the update-alternatives system. Ruby1.9.2 has the highest priority and hence will be selected by default. Choose your desired Ruby Version using the following command.

sudo update-alternatives --config ruby

If you have installed rdoc, ri, irb etc, make sure that you update their version too to match the ruby version you are using.

sudo update-alternatives --config rdoc
sudo update-alternatives --config irb
sudo update-alternatives --config ri

If you are not comfortable with the commandline, you could use the graphical alternatives system configuration tool, kalterantives for kde and galternatives for gnome.

sudo aptitude install galternatives
sudo aptitude install kalternatives

Next step is to create a script update-ruby-alternatives like the update-java-alternatives which already exists so that ruby environment can be seamlessly changed between different versions.

I also plan to add the latest ruby-gems package to the PPAs. Soon.

About Pratik Sinha

Linux Nerd, Socialist, Atheist, Adventuristic, Nature Lover, Geeky.


Leave a Reply to David Backéus Cancel reply