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?
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'
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.
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/.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With