I often need to deploy Ruby gems across many CentOS servers. I prefer to use the native OS package management tools (rpm + yum) rather than using Ruby gems.

Here's how to build RPMs from Ruby gems using gem2rpm.

I am assuming you have the necessary build tools installed (if not, yum install rpmdevtools) and have already created an RPM build environment, eg:

~/rpmbuild
|-- BUILD
|-- RPMS
|-- SOURCES
|-- SPECS
`-- SRPMS

First, make sure gem2rpm is installed:

yum install rubygem-gem2rpm

Then, grab the gem you want to convert to an RPM:

cd ~/rpmbuild/SOURCES
gem fetch capistrano

This will dump the gem file in the current directory, in this case: capistrano-2.5.14.gem.

Next, create a spec file:

gem2rpm capistrano-2.5.14.gem  > ../SPECS/rubygem-capistrano.spec

Finally, build the RPM(s):

rpmbuild -ba ../SPECS/rubygem-capistrano.spec

3 Comments

  1. Jordan Sissel says:

    I have a wrapper to gem2rpm that will download the gem and dependencies and build all as rpms.
    http://github.com/jordansissel/gem-packaging
    I've used it with good success at work for over 200 gems. As a bonus, it saves you (often) from having to understand rpm tools.

  2. robin says:

    Nice. I'll check that out if I need to do anything more with ruby gems.

  3. Adrian Bridgett says:

    Thank you kind sirs – very useful docs and tools.  The gem2rpm README leaves off enough of the detail that your nice simple walkthough saved a bit of head scratching and hunting around.

Leave a Reply