23 March 2011

pacgem: managing Ruby gems in Archlinux with ease.

Ruby is great. It's also designed to be platform independent and highly modular (i.e. through its gems system). The need to manage the gems and dependencies between them led to the development of its own package manager, rubygems, which works on any platform that can run ruby. However, here's the problem: what if your system already has a very good package manager (i.e. pacman)? Well, then you probably don't want to allow other things to start messing with what's in your file system.

One approach to dealing with this is to create a PKGBUILD for each and every gem (there are a few already in the AUR), but there are far more gems than can feasibly done by hand, and also unless an AUR helper which handles dependencies is used, it can be quite tiresome installing them all one by one. This solution is really not scalable, given the number of ruby gems that exist (22,366 according to rubygems.org).

Enter pacgem! This was created by minad and announced here on the Archlinux BBS.

It seems to me that pacgem makes managing ruby gems in Archlinux an absolute breeze. Basically, it creates a custom PKGBUILD for the specified gem, on the fly, handling dependencies between gems automatically.

Observe:

% pacgem nesta

==> Saving package files in /home/pete/arch/builds/pacgem/ruby-bundler
==> Resolving gems...
  -> (New) nesta-0.9.4: Ruby CMS, written in Sinatra
  -> (New) haml-3.0.25: An elegant, structured XHTML/XML templating engine. Comes with Sass, a similar CSS templating engine.
  -> (New) maruku-0.6.0: Maruku is a Markdown-superset interpreter written in Ruby.
  -> (New) syntax-1.0.0: Syntax is Ruby library for performing simple syntax highlighting.
  -> (New) RedCloth-4.2.7: RedCloth-4.2.7
  -> (New) sinatra-1.1.2: Classy web-development dressed in a DSL
  -> (New) rack-1.2.2: a modular Ruby webserver interface
  -> (New) tilt-1.2.2: Generic interface to multiple Ruby template engines
  -> (New) shotgun-0.9: reloading rack development server
==> Making package: ruby-haml 3.0.25-1 (Tue Mar 22 19:23:59 GMT 2011)
==> WARNING: Skipping dependency checks.
==> Retrieving Sources...
  -> Found haml-3.0.25.gem
==> Validating source files with sha256sums...
    haml-3.0.25.gem ... Passed
==> Extracting Sources...
==> Entering fakeroot environment...
==> Starting build()...
==> Installing gem...
Successfully installed haml-3.0.25
1 gem installed
==> Fixing gem installation...
==> Tidying install...
  -> Purging other files...
  -> Compressing man and info pages...
  -> Stripping unneeded symbols from binaries and libraries...
  -> Removing empty directories...
==> Creating package...
  -> Generating .PKGINFO file...
  -> Compressing package...
==> Leaving fakeroot environment.
==> Finished making: ruby-haml 3.0.25-1 (Tue Mar 22 19:24:03 GMT 2011)
==> Checking ruby-haml-3.0.25-1-any.pkg.tar.xz with namcap...

A short while and several pages of text later, the nesta gem and all the other gems it depends on are installed!

And, crucially, all the files are still under the management of pacman, each gem with its own package. E.g.

% pacman -Qo /usr/lib/ruby/gems/1.9.1/gems/nesta-0.9.4/Gemfile

/usr/lib/ruby/gems/1.9.1/gems/nesta-0.9.4/Gemfile is owned by ruby-nesta 0.9.4-1

% pacman -Qo /usr/lib/ruby/gems/1.9.1/gems/haml-3.0.25/Rakefile

/usr/lib/ruby/gems/1.9.1/gems/haml-3.0.25/Rakefile is owned by ruby-haml 3.0.25-1

Nice! Thanks minad!

Categories: All articles Ruby