Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I repackage a ruby gem with native extensions

Tags:

package

ruby

gem

I need to install a number of ruby gems (all with C extensions) on a production server which does not have any dev tools installed. I'd like to build gems on a dev server first and then repackage and install resulting native gems on production server.

However, there seems to be no standard methods to package gem with native extensions for redistribution. I am aware of rake-compiler, but none of the gems in concern works with it out of the box. Specifically, I am working with json-1.7.5, rb-inotify-0.8.8 and ffi-1.2.1 gems.

Any pointers on how to do this task or documentations on the subject are appreciated.

like image 301
ypz Avatar asked Oct 22 '22 21:10

ypz


1 Answers

Using Jordan Sissel's fpm you can take various input archives (including gems) and compile and package them as (among others) DEBs or RPMs.

An example to compile the json gem into a deb package follows:

cd /tmp
fpm -s gem -t deb json

This will download the latest version of the json gem and create a rubygem-json-1.5.7-1.amd64.deb archive in /tmp which you can install on your server. Note that the compile box and the final server need to be rather identical. At least the distribution and bitness, the ruby version and its file layout, and the available loadable libraries should be the same. Basically all the constraints your upstream distribution deals with...

That said, in the long term I found it much easier to just install a compiler on the target servers and use rbenv or rvm on the server. For most small and mid-size installations, it's much easier to handle as you don't need to pre-compile and ship everything to your servers.

like image 197
Holger Just Avatar answered Oct 27 '22 09:10

Holger Just