Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Ruby's load path externally

Tags:

ruby

rubygems

I have a custom Ruby library directory that I'd like to have automatically added to Ruby's load path whenever Ruby is executed. I know I can use the -I option to Ruby, but is there something like an environment variable that I can set that will globally determine Ruby's load path.

I want to install Ruby Gems on a Linux box where I don't have root privileges, so I need to have a Ruby load path in a non-standard location. I installed RubyGems per "Installing RubyGems in a User Directory", but the gem command isn't picking up the non-standard load path.

Maybe I'm missing something obvious here and making things harder for myself?

like image 539
Brian Ferris Avatar asked May 23 '09 07:05

Brian Ferris


People also ask

What is Ruby load PATH?

Ruby by default has a list of directories it can look through when you ask it to load a specific file. This is stored in a variable: $: This is the load path. It initially includes the libdir, archdir, sitedir, vendordir and some others and is information Ruby holds about itself. If you type ruby -e 'puts $LOAD_PATH'

What is setting PATH?

PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located. In general, each executing process or user session has its own PATH setting.

What should the PATH environment variable be?

The PATH environment variable is an important security control. It specifies the directories to be searched to find a command. The default systemwide PATH value is specified in the /etc/profile file, and each user normally has a PATH value in the user's $HOME/.


1 Answers

See the "Ruby and Its World" chapter from The Pickaxe Book, specifically the section on environment variables. Excerpt:

RUBYLIB    Additional search path for Ruby programs ($SAFE must be 0). DLN_LIBRARY_PATH   Search path for dynamically loaded modules. RUBYLIB_PREFIX   (Windows only) Mangle the RUBYLIB search path by adding this   prefix to each component. 
like image 177
Martin Carpenter Avatar answered Sep 18 '22 05:09

Martin Carpenter