Adding to the Ruby library path
Posted by admin, Sat Oct 20 04:40:23 UTC 2007
I couldn’t comment on David’s blog ( must be logged in… no way to log in provided :-( )
David Orriss Jr – The Delusion That People Care About What I Think » Blog Archive » How Ruby Finds Libraries
In Ruby not library management is not always as simple as running gem install. Some Ruby code is distributed simply as libraries. So where do you put these libraries? The clue is in the Ruby $LOAD_PATH variable.<br /> irb(main):001:0> puts $LOAD_PATH<br /> /usr/local/lib/ruby/site_ruby/1.8<br /> /usr/local/lib/ruby/site_ruby/1.8/i686-darwin8.10.1<br /> /usr/local/lib/ruby/site_ruby<br /> /usr/local/lib/ruby/1.8<br /> /usr/local/lib/ruby/1.8/i686-darwin8.10.1<br /> . => nil<br /> irb(main):002:0> <br />
This tells you that you can put your library code in any of the above listed directories and if Ruby still can’t find the code it will try the current directory you’re running code in before giving up. Personally I end up using the /usr/local/lib/ruby/1.8 folder.
I just found this little gem yesterday:
<br />$LOAD_PATH.unshift File.dirname(__FILE__) + '/lib'<br />Which, used in a Rakefile, will add the lib dir below the current directory to the load path.