Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to automatically append to $: variable in ruby to account for additional site_ruby locations?

Ruby is installed in /usr/local/ and using gem_install will properly install the new ruby files in to /usr/local/lib/ruby/site_ruby.

However there are some RPMs for ruby bindings to tools like shadow which we'd like to install and they install to /usr/lib/ruby/site_ruby (no local). Is there a standard way to tell ruby that this directory should also be included by default?

I know scripts could dynamically update $: or they could be called with -I but it seems like this is something that should be handled in the install.

Has anyone else found a clean way around this kind of problem?

thanks, chuck

share|improve this question

Set RUBYLIB in /etc/profile to include the paths you want.

Some dodgy example code:

#!/usr/bin/ruby -w

path_array = ARGV.dup
$:.each {|path| path_array << path }
path_string = "RUBYLIB=#{path_array.join(":")}"

begin"/etc/profile", "a") {|f| f.puts(path_string)}
rescue => e
  puts "error writing file: #{e}"
  exit 1

You could alias this script into your path and just call

$ add_ruby_path "<path1>" "<path2>" "<path3>"

Not very automatic on it's own though...

Perhaps you could create a file called /etc/rubypaths, and have the script run from cron, with a little modification? So instead of relying on ARGV, you do the following:

path_array = []
path_array ="/etc/rubypaths").split("\n")

But maybe what you want is for the OS to somehow "know" there is another site_ruby folder on the filesystem, and you want it to be added to $RUBYLIB. Not sure if that's do-able without you actual telling the OS your intention through something like a file in /etc.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.