Wednesday, April 04, 2007

c:0:Warning: require_gem is obsolete. Use gem instead.

After upgrading something in my rails environment--must be the gem tool, I think--it started giving me warnings here and there about "require_gem" being obsolete. Some of the warnings come from inside rails scripts. These can easily be fixed by searching for "require_gem" and replacing with "gem".

But my "rake" tool kept saying:
c:0:Warning: require_gem is obsolete.  Use gem instead.
Well, now I got around to fixing it. In your Ruby installation bin directory, there most probably is a rake.bat file (yes, I'm on a Windows box here). In this file, there is a small embedded Ruby script, which uses "require_gem". Fix this to "gem", and the deprecation warning goes away.


Anonymous said...

well, i have the following lines in rake.bat:

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]
gem 'rake', version
load 'rake'

what should be changed here exactly?

Per Olesen said...

Hmm, it looks like it has already been changed. Mine said:

require_gem 'rake', version

and I changed that into:

gem 'rake', version

and the warning disappeared.

I'm running rake 0.7.2 and rubygems 0.9.2.