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 I'm wondering if there is something like an environment variable that I can set that will globally determine Ruby's load path.
As an aside, my high level task is to install Ruby Gems on a Linux box where I don't have root, so I need to have a Ruby load path in a non-standard location. I've installed RubyGems per the directions at http://rubygems.org/read/chapter/3#page83 ("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?
Thank you! I used @MartinCarpenter's solution to run a specific/particular/single test method with minitest. Where I normally add the
test
directory to the$LOAD_PATH
with Rake::TestTask, e.g.,t.libs << 'test'
, I was able to do it with the command line, like so:I add
test
to$LOAD_PATH
becauseuser_test.rb
callsrequire 'test_helper'
to loadlib/test_helper.rb
.Make life easy and install RVM. It will install whatever version of Ruby you want and let you switch between them and it doesn't require root access. It has many other killer features you will become addicted to after using it for a while.
Make sure that you've placed the installed
bin
directory in your$PATH
for thegem
command to work. It should modify theRUBYLIB
itself, but if not, try Martin's answer to fix that.Then, you can have your gem home (where the gems that rubygems installs are stored) be local.
Just use
$GEM_HOME
(or set things up in your~/.gemrc
) and check that everything took withgem environment
.Try the Ruby and its world chapter from the pickaxe book, specifically the section on environment variables. Excerpt: