Update: see my recent post describing a better way to do this.

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:

|-- RPMS

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

6 thoughts on “Building RPMs from Ruby gems

  1. 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.

  2. good point! I’ll be upgrading my RPMs sholrty with curl support. @TomDV: Thanks for the feedback, the upgraded RPMs will fix the upgrade bug with your patch. Thanks! @gpmidi: The new RPM of 1.8 here will contain proxy. I don’t use it so I didn’t prioritize it, but I have a few requests to make it happen, so it’s coming. 🙂 Will post a update in a new post on my blog. Cheers guys! Keep the feedback coming!

  3. Hello,

    I was trying to build the RPM(s).Followed below steps :

    1)Installed gem to rpm

    gem install gem2rpm

    2) Converted the inspec  gem to rpm

    gem2rpm inspec-2.2.16.gem

    -This created a spec file : inspec-2.2.16.gemspec

    3)  Finally – Build the rpm

    rpmbuild -ba ./specifications/inspec-2.2.16.gemspec

    But am getting below error

    error: line 4: Unknown tag: Gem::Specification.new do |s|


  4. The gemspec file is not the same as the RPM spec file.

    You need to redirect the output of the gem2rpm command into an RPM spec file, eg:

    gem2rpm inspec-2.2.16.gem > rubygem-inspec.spec

    and then build the rpm from that file.



Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 


This site uses Akismet to reduce spam. Learn how your comment data is processed.