Question

On my ubuntu box, irb (ruby) gives a NameError when I try to use the mechanize gem:

$ 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 shows this:

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 shows it's installed:

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

it's in both paths in the filesystem:

$ 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 is up to date:

$ gem update --system
Updating RubyGems
Nothing to update

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

I have an up-to-date ruby:

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

Here's what ubuntu gems packages I have (note that I installed rubygems-update and ran 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
Was it helpful?

Solution

try to create the class using

WWW::Mechanize.new
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top