Rubygems on Ubuntu (with Puppet if you like)

Rubygems on Ubuntu (with Puppet if you like)

Debian packages and Rubygems: they get on like two angry cats in a sack. This post explains how you get Rubygems and Dpkg to play nicely on Ubuntu Hardy Heron.

What’s the issue? The Debian Packaging System (DPKG) is pretty good as packaging systems go. It’s had dependency support baked in for years, which means you can install one package, and any package that it needs, and so on. Rubygems is good in other ways. It’s a very convenient way to use and distribute other people’s Ruby code. Rubygems is optimised for developer convenience. The Debian system is optimised for stability. What happens when you try and make them work together? Bloodshed.

How do we cope? Most people get around it by installing the stock Rubygems into the Debian or Ubuntu system. This overwrites ‘/usr/bin/gem’ with a version of Rubygems that will install gems into the ‘/usr/’ directory on your system. What happens if you upgrade your Ubuntu distribution? The new version of Rubygems will overwrite the stock one. Because the Debian maintainers changed rubygems to install gems into a safer place (/var/lib/gems), you’ll probably notice installed gems disappear.

But what’s the downside? When the new Ubuntu LTS (Lucid Lynx) is released in April, you’ll probably want to upgrade. I’m finding Hardy harder to support as new tools arrive (couchdb is a good example). Is it time to get your systems sorted out now, so that you don’t break your apps on the upgrade?

How to do this? You can install the rubygems packages from Karmic Koala on Hardy Heron. Have a look at these instructions below. Note: this might make your Gems disappear. Do have some gem list –local output so you can put them back!

# HINT: run the sudo first or it will swallow any other text
sudo -s 
# rubygems and this scripts's dependencies
# if they are already installed, it won't reinstall
aptitude install wget ruby1.8 rdoc1.8  

# get the new gems on the system
cd /tmp
/usr/bin/wget   http://mirrors.kernel.org/ubuntu/pool/universe/libg/libgems-ruby/rubygems_1.3.5-1ubuntu2_all.deb
/usr/bin/wget http://mirrors.kernel.org/ubuntu/pool/universe/libg/libgems-ruby/rubygems1.8_1.3.5-1ubuntu2_all.deb
dpkg -i *.deb


# tell your system about them
cat <<HERE > /etc/profile.d/rubygems.sh
  export GEM_HOME=/var/lib/gems/1.8
  export GEM_PATH=/var/lib/gems/1.8
  PATH=${PATH}:${GEM_HOME}/bin
HERE

You’ll need to log out and back in again to see the changes. I also have this handy Puppet manifest to do all this en masse. Comment if you want me to publish.

Image thanks to Jijy

Update: I also want to help try and get rubygems working out of the box in either Debian or Ubuntu. Watch this space. Hopefully I’ll look at this over Xmas.

Update: Thanks to @auxesis for the comment. I’ve made a couple of changes to this post.

5 thoughts on “Rubygems on Ubuntu (with Puppet if you like)

  1. Great article, and a brilliant hack.

    Just two items of note:
    – Hardy won’t be obsolete when the next LTS comes out – it’s supported on the desktop for 3 years, and on the server for 5.
    – sudo -s is the more correct way of doing sudo su –

  2. […] a sack. This post explains how you get Rubygems and Dpkg to play nicely on Ubuntu Hardy Heron. More here What’s the issue? The Debian Packaging System (DPKG) is pretty good as packaging systems go. […]

  3. We Perl hackers have similar problems CPAN modules. i.e. a lot of important modules are packaged and can be installed via apt-get, but a lot are not.
    Debian provides dh-make-perl to get around the problem but it’s not perfect (cannot track dependencies, cannot install bundles,…).
    I end up saying to hell with it and use the native CPAN utility to manage Perl modules outside of the Linux package management system. To be honest it’s not that hard, but then I don’t tend to stretch Perl much

  4. PS I prefer ‘sudo -i’

  5. admin says:

    Alec,

    Interesting as I assumed that most (if not all) of the important Perl modules were packaged. Perhaps (because the Debian community was less familiar with Ruby), the threshold of annoyance is just lower for Ruby, and people tend to drop packages in favour of gems. I’m wondering how it works out for Python on Debian-based systems.

Comments are closed.

%d bloggers like this: