Last Updated: February 25, 2016
·
4.979K
· samhalicke

quickly build native ruby packages with fpm + rbenv

three things are necessary for this:

@jordansissel's amazing fpm

@sstephenson's equally wonderful rbenv and ruby-build

This assumes you have a working rbenv setup.

$ CONFIGURE_OPTS='--enable-shared' rbenv install 1.9.3-p392
$ cd ~/.rbenv/versions/1.9.3-p392
$ fpm -s dir -t rpm --prefix /usr -n ruby \
   --version 1.9.3 .

That is quite literally it. You'll end up with a package named

ruby-1.9.3-1.x86_64.rpm

To verify what this RPM will install:

rpm -qpl ruby-1.9.3-1.x86_64.rpm

The version number could use some tweaking (see fpm -h) but in the interest of brevity I've kept it short. One caveat:

  • If you use the full directory path instead of cd, the RPM package will reflect that and you'll have the rbenv tree under /usr in your package.
  • rbenv by default builds libyaml, but not the shared ruby libs.

Note that fpm is a great tool and you can easily switch out various packaging output formats (.deb being the obvious alternative).

Why would you do this?

  • if you have to lock the 'system ruby' or override it in some way, which is often needed to guarantee the use of a certain version without writing wrapper scripts & symlinking things (that comes with its own set of problems).

  • You know that your other packages will work with the Ruby you're building, and don't care about dependencies. In that case use:

    --provides ruby --provides ruby-libs --provides ruby-irb

  • You should probably not use --provides ruby(abi). Ever.

  • You generally know what you're doing. This is just a fast way to do it. =]

  • This is more than enough rope to hang yourself. =]

Enjoy!

1 Response
Add your response

I think you might be missing a step here. Specifically, when I use this method I get this:

$ ruby -e 'puts "hi"'
internal:gem_prelude:1:in require': cannot load such file -- rubygems.rb (LoadError) from <internal:gem_prelude>:1:in<compiled>'

Any idea what I might be missing? Also, the cp gem fpm doesn't make sense to me. I should just do a gem install fpm && rbenv rehash right?

over 1 year ago ·