我对路径如何与宝石一起使用有点困惑。这是我困惑的核心:
>> require 'rubygems'
=> false
>> Gem.available?('money')
=> true
>> require 'money'
LoadError: no such file to load -- money
from (irb):3:in `require'
from (irb):3
from /usr/bin/irb:12:in `<main>'
>> Gem.available?('pony')
=> false
>> require 'pony'
=> true
这是由irb 0.9.5(05/04/13)
This 特别令人困惑,因为gem list --local
产量:
*** LOCAL GEMS ***
albino (1.0)
bcat (0.5.2)
builder (2.1.2)
bundler (1.0.0)
classifier (1.3.3)
diff-lcs (1.1.2)
directory_watcher (1.3.2)
fast-stemmer (1.0.0)
gdata (1.1.1)
gdata2 (0.1)
github-markup (0.5.0)
gollum (1.0.1)
google4r-checkout (1.0.6.1)
grit (2.2.0)
jekyll (0.7.0)
kwalify (0.7.1)
liquid (2.2.2)
maruku (0.6.0)
mime-types (1.16)
mocha (0.9.8)
money (3.0.5)
mustache (0.11.2)
nokogiri (1.4.3.1)
rack (1.2.1, 1.1.0)
rake (0.8.7)
rubygems-update (1.3.7)
sanitize (1.2.1)
sinatra (1.0)
syntax (1.0.0)
unicorn (1.1.3)
其中明显包含 money
但不 pony
包含。
这是输出gem env
:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.1 (2010-01-10 patchlevel 378) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: /usr/bin/ruby1.9.1
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/lib/ruby/gems/1.9.1
- /home/aresnick/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
如果不清楚,gem
并且ruby
使用相同的红宝石,即:
aresnick@dror:~$ which ruby
/usr/bin/ruby
aresnick@dror:~$ ls -al $(which ruby)
lrwxrwxrwx 1 root root 22 2010-08-28 20:08 /usr/bin/ruby -> /etc/alternatives/ruby
aresnick@dror:~$ ls -al /etc/alternatives/ruby
lrwxrwxrwx 1 root root 18 2010-08-28 20:08 /etc/alternatives/ruby -> /usr/bin/ruby1
我怀疑问题出在正在查看的路径上,特别是因为我可以访问和无法访问的其他宝石,例如gdata
不可用并且sinatra
是。. .
aresnick@dror:~$ gem which pony
/var/lib/gems/1.9.1/gems/pony-1.0/lib/pony.rb
aresnick@dror:~$ gem which money
/usr/lib/ruby/gems/1.9.1/gems/money-3.0.5/lib/money.rb
aresnick@dror:~$ gem which sinatra
/var/lib/gems/1.9.1/gems/sinatra-1.0/lib/sinatra.rb
aresnick@dror:~$ gem which gdata
/usr/lib/ruby/gems/1.9.1/gems/gdata-1.1.1/lib/gdata.rb
aresnick@dror:~$ irb
>> require 'sinatra'
=> true
>> require 'gdata'
LoadError: no such file to load -- gdata
from (irb):2:in `require'
from (irb):2
from /usr/bin/irb:12:in `<main>'
所以,我认为/usr/lib/ruby/gems/1.9.1
宝石没有被发现,而/var
那些宝石是。我确信使用符号链接可以解决这个问题,但我想知道a)为什么会发生这种情况,b)这些路径在哪里设置以及如何设置它们?