Print Page

Friday, March 5, 2010

Getting RUBYLIB right for custom ruby & rubygems install

We need to have a server with a custom ruby installation alongside the system ruby, with a later version of ruby & rubygems and an local gem collection, to port one rails application at a time to ruby 2.3.5 on the same host as others are running the old setup.

I thought I had the whole thing working when I got rake and rails to install via rubygems but then when I hit the mysql gem and alternately the ruby-mysql gem, I got stuck with errors like:

For mysql gem:
ERROR: Error installing mysql:
mysql requires Ruby version >= 1.8.6.

For ruby-mysql gem
ERROR: Error installing ruby-mysql:
ruby-mysql requires Ruby version >= 1.8.7.

This was weird, since I had installed 1.8.7p249 and sourced my script to set the environment for it.

Running gem env showed me rubygems even though it had my custom ruby in its shebang line for the gem command was actually using the old 1.8.5 system install, which at least explained why the errors cropped up complaining about version. Another symptom of having rubygems 1.3.6 installed by the later version of ruby running under the 1.8.5 it defaulted to was that 'gem help' worked but 'gem help ' failed.

Googling around the net, I found a few postings from people in analogous situations who advocated removing the old installation of ruby. Not an option for us, so I dug deeper into the docs for rubygems and the code. Eventually this led me to the $RUBYLIB environment variable. My script had it set to $PREFIX/lib, where setup.rb had put the rubygems files. So it was missing access to some of the other parts that should have been in RUBYLIB.

This is the part of the environment setup file I source now to use the new ruby that fixed the problem. It first has the two standard directories for ruby files, then the directory Rubygems installed into:

RUBYLIB=$PREFIX/lib/ruby/1.8:$PREFIX/lib/ruby/site_ruby/1.8:$PREFIX/lib
export RUBYLIB

Using it, 'gem env' reports the correct ruby in use, ruby-mysql installs, and 'gem help install' works.