Sunday, February 3, 2008


require_gem error


c:/ruby/bin/rake.bat:24: undefined method `require_gem' for main:Object (NoMethodError)

I encountered this error when I installed rails version 2.0.2. I wanted to use
call rake db:migrate

when I encountered the error
"c:/ruby/bin/rake.bat:24: undefined method `require_gem' for main:Object (NoMethodError)"

I was able to remove this error by following way:

1. open the rake.bat file. This file is present in the bin folder of ruby. For me the path was c:rubybinrake.bat
2. The file will look like the following:
@echo off
if not "%~f0" == "~f0" goto WinNT
ruby -Sx "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofruby
:WinNT
"%~d0%~p0ruby" -x "%~f0" %*
goto endofruby
#!/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'

__END__
:endofruby


3. You need to replace the line
require_gem 'rake'version
with
gem 'rake',version

4. The file rake.bat will now look like
@echo off
if not "%~f0" == "~f0" goto WinNT
ruby -Sx "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofruby
:WinNT
"%~d0%~p0ruby" -x "%~f0" %*
goto endofruby
#!/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
gem 'rake', version
load 'rake'

__END__
:endofruby



Hope that this should solve your problem

1 comment:

Unknown said...

wow terrific it works!! thanks man.