Fixing: undefined method `require_gem’ for main:Object (NoMethodError)
After upgrading to the newest version of rails (2.2.2) I was getting this error:
administrator@shuttle:~$ rails -v/usr/bin/rails:17: undefined method `require_gem' for main:Object (NoMethodError)
Anytime I called “rails” I would get this error and could not get past.
Here is the fix
administrator@shuttle:~/$ sudo vim /usr/bin/rails
Look for anywhere in the file that calls “require_gem”, I found it in only one spot:
require_gem 'rails', version
And change “require_gem” to just “gem” so:
gem 'rails', version
Save and when you run “rails -v” you should see this:
administrator@shuttle:~/$ rails -vRails 2.2.2
You should no longer get the error with running “rails”
Posted on February 14, 2009 at 9:42 am by nickdenardis · Permalink
In: rails, software · Tagged with: fix, rails, ruby
In: rails, software · Tagged with: fix, rails, ruby

on June 17, 2009 at 10:03 am
Permalink
[...] Nach kurzer Suche fand ich die Lösung für ein ähnliches Problem. Anstelle von rails nimmt man sich hier einfach rake vor (auf meinem Debian-Server unter [...]
on January 5, 2010 at 2:24 am
Permalink
I get this error with rake. The require_gem method is the problem again. However your solution fixes it.
#!/usr/bin/ruby
#
# This file was generated by RubyGems.
#
# The application ‘rake’ is installed as part of a gem, and
# this file is here to facilitate running it.
#
require ‘rubygems’
version = “> 0″
if ARGV.size > 0 && ARGV[0][0]==95 && ARGV[0][-1]==95
if Gem::Version.correct?(ARGV[0][1..-2])
version = ARGV[0][1..-2]
ARGV.shift
end
end
require_gem ‘rake’, version
load ‘rake’