Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add $LOAD_PATH externally

Tags:

ruby

load-path

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!

like image 798
SwiftMango Avatar asked Apr 12 '12 03:04

SwiftMango


2 Answers

RUBYLIB environment variable is a colon separated list of paths which ruby will prepend the 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.

like image 85
dbenhur Avatar answered Sep 23 '22 10:09

dbenhur


$ export RUBYLIB=/tmp/test
$ irb
ruby-1.9.2-p290 :001 > puts $LOAD_PATH
/tmp/test
...
like image 3
Prathan Thananart Avatar answered Sep 20 '22 10:09

Prathan Thananart