Tuesday, December 15, 2009

LoadError: no such file to load -- mechanize

Problem

root@khojguru:~# irb
irb(main):001:0> require 'mechanize'
LoadError: no such file to load -- mechanize
        from (irb):1:in `require'
        from (irb):1

Cause

Because the of versioned nature of the gems repository, RubyGems doesn’t store the library files directly in standard library search path. It adds the necessary gem packages to the library search path as needed at run time.
This means that RubyGems must be loaded before any gem libraries are accessable.

Solution

Add this
export RUBYOPT=rubygems
to
~/.bashrc

Reload

To reload the changes you need to fire...
root@khojguru:~#source ~/.bashrc

Check it out

irb(main):003:0> require 'mechanize'
=> true

7 comments:

  1. Thats a really handy tip! I was sick of typing "require 'rubygems'" every time I started irb. Nice!

    ReplyDelete
  2. Wonderful, tip! Thank you

    ReplyDelete
  3. Not working for me..
    Again same error, no such file to load --mechanize

    ReplyDelete
    Replies
    1. There was typo: do "source ~/.bashrc" instead of "source ~/.basrc"

      Delete
  4. You are awesome. It fixes my annoying problem!

    ReplyDelete

  5. Thanks for sharing...

    here is one of the good Online Food Deals site in india: Online Deals in Delhi at Khaugalideals.com

    ReplyDelete