'require'看起来和'Gem.available'之间有什么区别?寻找宝石?

时间:2010-09-04 18:44:50

标签: ruby rubygems gem irb

我对路径如何处理宝石感到有些困惑。这是我困惑的核心:

>> 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)运行这一点尤为令人困惑,因为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/

如果不清楚,gemruby使用相同的红宝石,即:

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宝石是。{1}}宝石。我确定用符号链接可以解决这个问题,但我想知道a)为什么会这样,b)这些路径设置在哪里以及如何设置它们?

1 个答案:

答案 0 :(得分:0)

我在Debian系统上遇到了类似的问题,我猜你正在使用或者是基于系统,因为你正在使用替代品,问题是我通过apt-get安装了rubygems然后通过源安装更新版本。

搞好事情。

Debian和rubygems团队之间存在某种“宗教”战争,因此在Debian上安装rubygems更容易。

我对发生的事情没有任何解释。 :(