views:

1444

answers:

4

Ok, I've just spent the 4 hours trying to figure this one out without success. I've tried all the usual suspects and googled every combination of ruby 1.9.1, load path, gems, mac os x,freebsd,prawn and other stuff. The bottom line is this:

When I compile ruby1.9.1-p129 from sources on mac os x 10.5, the default load path ($:) I get is:

ruby -e "puts $:"
/usr/local/lib/ruby/gems
/usr/local/lib/ruby/site_ruby/1.9.1
/usr/local/lib/ruby/site_ruby/1.9.1/i386-darwin9.7.0
/usr/local/lib/ruby/site_ruby
/usr/local/lib/ruby/vendor_ruby/1.9.1
/usr/local/lib/ruby/vendor_ruby/1.9.1/i386-darwin9.7.0
/usr/local/lib/ruby/vendor_ruby
/usr/local/lib/ruby/1.9.1
/usr/local/lib/ruby/1.9.1/i386-darwin9.7.0
.

when I install the prawn gem, for example, I get:

gem which prawn
(checking gem prawn-0.5.0.1 for prawn)
/prawn.rb

and when I try to require it I get:

ruby -e "require 'prawn'"
-e:1:in `require': no such file to load -- prawn (LoadError)
    from -e:1:in `'

The only way I've been able to resolve this is by doing something stupid like this:

$: << "/usr/local/lib/ruby/gems/1.9.1/gems/prawn-0.5.0.1/lib"

which, of course, is utterly ridiculous. So the question is how do I get ruby 1.9.1 to recognize and follow the correct gems path? I've never had this issue with 1.8.7 so I'm assuming it 1.9.1 specific. I feel I'm missing something completely obvious here and any help would be much appreciated!

+2  A: 
require 'rubygems'
require 'prawn'

Unless things have changed in 1.9 that you no longer need to require rubygems first.

Aaron Hinni
ruby 1.9 no longer requires (pun intended) rubygems but just to be thorough I tried that as well without success
ennuikiller
+5  A: 

setting GEM_PATH=/usr/local/lib/ruby/gems/1.9.1

solved the problem. I knew it was something simple. Just aggravates me that it took ALL DAY to figure out!! This is due to never having this issue with 1.8.7 and of course NOT RTFM!!

This just proves what should be another law of programming:

ALWAYS INVEST THE TIME TO RTFM!!

ennuikiller
Glad you got it worked out!
Aaron Hinni
+2  A: 

same problem on kubuntu karmic.

installation:

$ sudo apt-get install build-essential ruby1.9.1-full libsqlite3 libsqlite3-dev rubygems1.9
$ sudo gem install sqlite3-ruby rails thin --no-rdoc --no-ri

result:

$ ruby -e "require 'rubygems'; require 'sqlite3'" 
-e:1:in `require': no such file to load -- sqlite3 (LoadError)
        from -e:1:in `<main>'

solution:

$ export GEM_PATH=/usr/lib/ruby1.9.1/gems/1.9.1/
airy
A: 

I'm looking for a different answer to the same problem. In some situations (ie. system start up tasks) setting environment variables before ruby runs is impossible.

Is there some way in running ruby (v >= 1.9.1) code to require gems? Without setting GEM_PATH?

Simon
As stated in the original question you can push the required gem path to $:
ennuikiller
The "solution" was: Gem.activate('gem_name'); require('gem_name'); Notably this GEM_PATH issue goes away with 1.9.2.
Simon