RB_USER_INSTALL to the rescue

Posted by Robert Gogolok Sat, 10 Oct 2009 01:23:00 GMT

If you try to install gems with extensions as non-root user, you will fail (in general)!

For example, installing hpricot results in the following error message on my FreeBSD 7.2 machine:

make install
/usr/bin/install -c -o root -g wheel -m 0755 hpricot_scan.so /home/username/GEMS/gems/hpricot-0.8.1/lib
install: /home/username/GEMS/gems/hpricot-0.8.1/lib/hpricot_scan.so: chown/chgrp: Operation not permitted
*** Error code 71

The file rbconfig.rb contains some info how you're ruby version has been built.

$ pkg_info -L ruby-1.8.\* | grep rbconfig.rb
/usr/local/lib/ruby/1.8/i386-freebsd7/rbconfig.rb

It containes the following interessting line:

CONFIG["INSTALL"] = ENV['RB_USER_INSTALL'] ? '/usr/bin/install -c' : '/usr/bin/install -c -o root -g wheel'

So, by default, gem extensions will be installed as user root of group wheel on my system. On the other hand, if RB_USER_INSTALL gets set as environment variable, gems will install with the permissions of the user calling gem install!