ruby:irb给NameError尝试使用mechanize gem(ubuntu)

时间:2010-08-06 06:29:54

标签: ruby mechanize gem nameerror

在我的ubuntu框中,当我尝试使用mechanize gem时,irb(ruby)会给出一个NameError:

$ irb
irb(main):001:0> require 'mechanize'
=> true
irb(main):002:0> Mechanize.new
NameError: uninitialized constant Mechanize
    from (irb):2
    from :0

gem env显示了这个:

RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.7
  - RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /usr/bin/ruby1.8
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.8
     - /var/lib/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - :gempath => ["/var/lib/gems/1.8", "/usr/lib/ruby/gems/1.8"]
  - REMOTE SOURCES:
     - http://rubygems.org/

gem list显示已安装:

$ gem list mech
*** LOCAL GEMS ***
mechanize (1.0.0)

它位于文件系统中的两个路径中:

$ ls -1 /var/lib/gems/1.8/gems/ |grep mech
mechanize-1.0.0

$ ls -1 /usr/lib/ruby/gems/1.8/gems |grep mech
mechanize-1.0.0

RubyGems是最新的:

$ gem update --system
Updating RubyGems
Nothing to update

# gem list rubygems
*** LOCAL GEMS ***
rubygems-update (1.3.7)

我有一个最新的红宝石:

ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]

这是我拥有的ubuntu gems包(注意我安装了rubygems-update并运行了update_rubygems):

# dpkg -l rubygems*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name               Version            Description
+++-==================-==================-====================================================
ii  rubygems           1.3.5-1ubuntu2     package management framework for Ruby libraries/appl
ii  rubygems-doc       1.3.5-1ubuntu2     package management framework for Ruby libraries/appl
ii  rubygems1.8        1.3.5-1ubuntu2     package management framework for Ruby libraries/appl

1 个答案:

答案 0 :(得分:3)

尝试使用

创建类
WWW::Mechanize.new