Question

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!

Was it helpful?

Solution

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!!

OTHER TIPS

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/
require 'rubygems'
require 'prawn'

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

Next time you have such an issue, don't forget to run gem env from the command line. This is what happens on Windows, but the principle is much the same:

C:\Documents and Settings\a.grimm>gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.5
  - RUBY VERSION: 1.9.1 (2010-01-10 patchlevel 378) [i386-mingw32]
  - INSTALLATION DIRECTORY: C:/Ruby19/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: C:/Ruby19/bin/ruby.exe
  - EXECUTABLE DIRECTORY: C:/Ruby19/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-mingw32
  - GEM PATHS:
     - C:/Ruby19/lib/ruby/gems/1.9.1
     - C:/Documents and Settings/a.grimm/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://gems.rubyforge.org/

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top