1

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

cclark
  • 567
  • 2
  • 6
  • 14

1 Answers1

0

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
  File.open("/etc/profile", "a") {|f| f.puts(path_string)}
rescue => e
  puts "error writing file: #{e}"
  exit 1
end

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 = IO.read("/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.