8

I understand that to add a path to $LOAD_PATH just do

$LOAD_PATH.unshift(path)

But I have to add this line to every program I wrote. Is there anyway to add it to the system level?

I tried to search a bit on the startup script for Ruby, but did not find the answer. I tried to add this line to kernel/common/module.rb, ruby_constants.rb, loader.rb,etc. but neither works.

In which file should I add this line to?


Updates:

I am using ubuntu 10.04 and Rubinius. There is no system variable called RUBYLIB.

Tried creating one but did not work. But I realize I made a mistake, and forgot to add the variable in bash script .bashrc. After adding the variable, it all works fine!

Seph
  • 1,084
  • 13
  • 22
SwiftMango
  • 15,092
  • 13
  • 71
  • 136

2 Answers2

9

RUBYLIB environment variable is a colon separated list of paths which ruby will prepend to the standard LOAD_PATH. ruby -I path on the command line is also the same as $LOAD_PATH.unshift 'path' in your code. Ruby will also process options from environment var RUBYOPT.

Richie Thomas
  • 3,073
  • 4
  • 32
  • 55
dbenhur
  • 20,008
  • 4
  • 48
  • 45
  • I thought they removed RUBYLIB after 1.9? I am using Rubinius and did not find RUBYLIB. And ruby -I is annoying too – SwiftMango Apr 12 '12 at 04:23
  • I just double checked. There is no RUBYLIB or RUBYOPT env var. I am using ubuntu 10.04 and Rubinius 2.0. I also tried adding a system variable but it did not work. – SwiftMango Apr 12 '12 at 04:53
  • @texasbruce maybe you should edit your question to show what you tried, and how it didn't work. – Andrew Grimm Apr 12 '12 at 05:03
  • @texasbruce rbx honors RUBYLIB just as MRI rubies do. Here's the [source](https://github.com/dbenhur/rubinius/blob/master/kernel/loader.rb#L115) – dbenhur Apr 12 '12 at 15:04
3
$ export RUBYLIB=/tmp/test
$ irb
ruby-1.9.2-p290 :001 > puts $LOAD_PATH
/tmp/test
...
Prathan Thananart
  • 4,007
  • 3
  • 19
  • 18