1

我有一个简单的脚本:

require 'rubygems'
require 'mechanize'
p 'Success!'

当我运行脚本时,我得到:

/Users/.../.rvm/rubies/ruby-1.9.3-p385/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mechanize.rb (LoadError)
from /Users/.../.rvm/rubies/ruby-1.9.3-p385/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from test.rb:2:in `<main>'

无奈之下,我安装了 RVM 并从系统 1.8.7 更新了 ruby​​。然而,我仍然遇到与安装 rvm 之前相同的错误。我现在正在运行:

mute:nfg ..$ ruby -v
ruby 1.9.3p385 (2013-02-06 revision 39114) [x86_64-darwin10.8.0]

irb 报告相同:

1.9.3p385 :001 > require 'rubygems'
 => false 
1.9.3p385 :002 > require 'mechanize'
LoadError: cannot load such file -- mechanize
from /Users/../.rvm/rubies/ruby-1.9.3-p385/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/../.rvm/rubies/ruby-1.9.3-p385/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):2
from /Users/../.rvm/rubies/ruby-1.9.3-p385/bin/irb:16:in `<main>'

我已经从项目目录中多次使用 sudo 和不使用 sudo 重新安装了 mechanize。

我尝试手动要求 gem 及其完整路径。

mute:nfg ..$ ruby -l ~/.gems/gems/mechanize-2.5.1/lib/mechanize.rb
/Users/../.rvm/rubies/ruby-1.9.3-p385/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mime/types (LoadError)
from /Users/../.rvm/rubies/ruby-1.9.3-p385/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/../.gems/gems/mechanize-2.5.1/lib/mechanize.rb:4:in `<main>'

(我也尝试过安装 mime-types。)

RVM 很好地列出了 gem:

mute:nfg ..$ rvm all do gem list
*** LOCAL GEMS ***
...
libxml-ruby (2.3.3, 1.1.2)
mechanize (2.5.1)
mime-types (1.21, 1.19)
...

和宝石一样:

mute:nfg ..$ gem list
*** LOCAL GEMS ***
...
libxml-ruby (2.3.3, 1.1.2)
mechanize (2.5.1)
mime-types (1.21, 1.19)
...

奇怪的是,$GEM_PATHs~/.rvm/gems/ruby-1.9.3-p385和看起来大多是空的(第一个中有两个宝石,最后一个都没有)。但是,GUI JewelleryBox 确认所有三个宝石组都包含.~/.rvm/gems/ruby-1.9.3-p385@global~/.rvm/gems/ruby-1.9.3-p385@projectMechanize

编辑:这是 gem env 的结果:

RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.25
  - RUBY VERSION: 1.9.3 (2013-02-06 patchlevel 385) [x86_64-darwin10.8.0]
  - INSTALLATION DIRECTORY: /Users/../.gems
  - RUBY EXECUTABLE: /Users/../.rvm/rubies/ruby-1.9.3-p385/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/../.gems/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-10
  - GEM PATHS:
     - /Users/../.gems
     - /Users/../.gem
     - /usr/lib/ruby/gems/1.8
     - /Library/Ruby/Gems/1.8
     - /usr/bin
  - GEM CONFIGURATION:
 - :update_sources => true
 - :verbose => true
 - :benchmark => false
 - :backtrace => false
 - :bulk_threshold => 1000
 - :sources => ["http://gems.rubyforge.org/", "http://gems.github.com"]
 - "gemhome" => "/Users/../.gems"
 - "gempath" => ["/Users/../.gem", "/usr/lib/ruby/gems/1.8", "/Library/Ruby/Gems/1.8", "/usr/bin"]
- REMOTE SOURCES:
 - http://gems.rubyforge.org/
 - http://gems.github.com

任何人都可以帮忙吗?

4

1 回答 1

1

您的环境设置为对 gems 使用自定义路径,这会使 ruby​​gems 在您安装到不可用的地方时感到困惑PATH

运行rvm get head并仔细阅读输出,它会警告您有关*gemrc中断 ruby​​gems / RVM中的条目

于 2013-02-24T14:07:02.600 回答