Undefined method `require_gem' for main:Object

Posted on 31 January 2008

To update an old app to Rails 2.x you will need to change 'require_gem' to just 'gem'.

Otherwise you will get: Undefined method `require_gem' for main:Object

About Paul

Paul works for Kyan web design agency in Surrey, UK as a Ruby on Rails developer.

Follow Paul on Twitter

Email: paulsturgess [at] gmail.com

Read more articles in the archive →

Comments...

  • I recently had this problem. I think the new version of rubygems use gem instead of require_gem. It's not necessarily a Rails 2.x issue.

    rupher at 31 Jan 08 at 07:50

  • Actually, the new version of gems only requires a "require." No gem or require_gem method needed. Just do this: require 'rubygems'; require 'yourlib';

    Jeremy at 01 Feb 08 at 18:05

  • gem install --remote rake

    I have been your problem before, and after i did it, it's worked well.

    Reinhart at 09 Apr 08 at 00:25

  • Great. Thanks, all. I was stumbling blindly, then found this.

    ken at 10 Apr 08 at 19:35

  • I had to use "gem" to get this to work:

    #!/usr/bin/env ruby

    require 'rubygems'
    gem 'multi'
    # require 'multi' # didn't work
    require 'amulti'

    multi(:fib,0){1}
    multi(:fib,1){1}
    multi(:fib,Integer){|n|fib(n-1)+fib(n-2)}

    puts fib(4)

    Rob at 05 Jun 08 at 02:00

  • sorry the formatting was messed up. I pasted the code on these to pastebins:
    http://code.bulix.org/ckqjv9-66832
    http://www.pastebin.org/40737

    Rob at 05 Jun 08 at 02:22

  • I am new to RoR. After getting everything installed, I ran ...
    rails sandbox

    I received the error you reported. This is what fixed the issue for me ...
    gem update rails

    jeff at 10 Jun 08 at 09:44

  • Thanks!!! Saved me a million!!

    swinful at 28 Jul 08 at 19:20

  • probably not because of Rails 2.0,
    but rather because of gem 1.0.1.

    "require_gem" works for gem 0.9.0
    "gem" works for both gem 0.9.0 and 1.0.1

    Heinz at 25 Aug 08 at 08:01

  • Seems pretty high-handed to gratuitously break running code. And I sure can't see any pressing reason to all of a sudden drop require_gem. I guess these guys are good a developing new code and not so good at maintaining old code.

    Jon Seidel at 30 Apr 09 at 16:17

  • on windows I had to create Env variable "RUBYOPT" and set to "rubygems"

    jw at 06 Jan 12 at 21:17

Got something to say?