Gem Path Issue: RubyGems looking in the wrong place
When I require certain gems, some of them work and some of them don't work. They seem to install find and I can do a gem list and they ar开发者_开发百科e there. However, when I try to run them in Irb or run my ruby programs from the terminal I get the following:
LoadError: no such file to load -- sanitize
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:54:in `gem_original_require'
And so I followed the guide on RubyGems and everything seems fine:
noahclark$ gem list sanitize
*** LOCAL GEMS ***
sanitize (2.0.3)
noahclark$ ruby -rubygems -e 'require "sanitize"'
noahclark$
noahclark$ which ruby
/opt/local/bin/ruby
noahclark$ gem env | grep 'RUBY EXECUTABLE'
- RUBY EXECUTABLE: /opt/local/bin/ruby
So then I tried:
noahclark$ which gem
/opt/local/bin/gem
noahclark$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.10
- RUBY VERSION: 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin10]
- INSTALLATION DIRECTORY: /opt/local/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /opt/local/bin/ruby
- EXECUTABLE DIRECTORY: /opt/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-10
- GEM PATHS:
- /opt/local/lib/ruby/gems/1.8
- /Users/noahclark/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
You can see that which gem and gem environment are looking at two separate directories. I hunted around for a fix and I could only find something that suggested adding export PATH=$PATH:/opt/local/bin/gem to my .bashrc file. This did not fix it.
How should I go about fixing this?
Based on the path in your error message, your irb and apps are probably using the default system ruby.
What does which irb
show?
And what is the commandline you use to run your apps?
You may need to adjust the shebang line (the first line which starts with "#!") of your scripts to use /opt/local/bin/ruby.
Try adding this to your .bashrc?
export PATH=/opt/local/bin/gem:$PATH
That gives the your new gem path the first crack rather than the current, incorrect default.
精彩评论