This project is archived and is in readonly mode.

#462 ✓committed
Ben Oakes

Loading environment fails with an outdated version of RubyGems while using config.gem "some_gem"

Reported by Ben Oakes | June 20th, 2008 @ 09:35 PM | in 2.1.1

I spent quite a bit of today trying to figure out an issue that was only appearing on our Linux boxes, but not the Mac OS X machines. This concerns the new gem dependencies feature (i.e. "config.gem" in environment.rb). (More specifically, we are unpacking into vendor/gems, but that doesn't seem related to the problem.)

After a lot of debugging, I found out that the issue was differing versions of the RubyGems utility ("gem" on the command line) and is likely not related to differing operating systems. The two Linux machines I was testing on had version 0.9.x rather than the newer 1.1.1 of the Macs. (Mac users may also have this older version if they have not updated, of course.) An old version of RubyGems will cause Rails to fail at the very start because the environment cannot be set up, but only if a "config.gem" dependency is specified.

To reproduce:

Try running "rake test" (or almost anything else) on a Rails project which does not use Gem Dependencies on a machine that has RubyGems < 1.1.1 (not sure of the exact version -- 0.9.4 and 0.9.2 were causing problems for us.) Verify that this works without problems. (To check your version, use gem --version.)

Add any gem dependency, such as:

config.gem "httpclient"

You should receive an error such as the following (which is from running rake test):

/usr/lib64/ruby/site_ruby/1.8/rubygems/version.rb:237:in `initialize': undefined method `collect' for nil:NilClass (NoMethodError)
    from /usr/lib64/ruby/site_ruby/1.8/rubygems/version.rb:29:in `new'
    from /usr/lib64/ruby/site_ruby/1.8/rubygems/version.rb:29:in `initialize'
    from /home/oakes/trunk/config/../vendor/rails/railties/lib/rails/gem_dependency.rb:104:in `new'
    from /home/oakes/trunk/config/../vendor/rails/railties/lib/rails/gem_dependency.rb:104:in `specification'
    from /home/oakes/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/core_ext/symbol.rb:11:in `__send__'
    from /home/oakes/trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/core_ext/symbol.rb:11:in `to_proc'
    from /home/oakes/trunk/config/../vendor/rails/railties/lib/rails/plugin/locator.rb:81:in `map'
    from /home/oakes/trunk/config/../vendor/rails/railties/lib/rails/plugin/locator.rb:81:in `plugins'
     ... 17 levels...
    from /usr/lib64/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb:5:in `load'
    from /usr/lib64/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb:5
    from /usr/lib64/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb:5:in `each'
    from /usr/lib64/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb:5

Then update RubyGems (sudo gem update --system). Everything should run normally.

Something in Rails (possibly Rake) should check for the RubyGems version and warn that it should be updated if it's too old. That is, something like this:

local_version = %x[gem --version].chomp

if REQUIRED_VERSION != local_version
  puts "You need to update the RubyGems utility to #{REQUIRED_VERSION} using the following"
  puts ""
  puts "    sudo gem update --system"

Comments and changes to this ticket

  • jeff

    jeff June 26th, 2008 @ 04:57 PM

    • Tag set to 2.1


    it would be nice to have some kind of warning or failure if rails is incompatible with gem version < x

  • David Lowenfels

    David Lowenfels July 9th, 2008 @ 02:06 AM

    +1 rails definitely needs a patch to fix this... it is terrible to have things fail with a cryptic error

  • David Lowenfels

    David Lowenfels July 9th, 2008 @ 02:46 AM

    Simple fix: rails already was requiring rubygems >= 0.9.4.

    This patch makes it require rubygems >= 1.1.1

  • David Lowenfels
  • David Lowenfels

    David Lowenfels July 16th, 2008 @ 11:00 AM

    I don't see the attachment from my last comment. Can only admins see it??

    I'm attaching it again, and including in this comment. Sorry if it ends up being a repeat.

    From ec3108863e6fa7613fb251f1dd916c9a3e668665 Mon Sep 17 00:00:00 2001
    From: David Lowenfels
    Date: Tue, 8 Jul 2008 18:34:20 -0700
    Subject: [PATCH] requiring rubygems version 1.1.1
     railties/environments/boot.rb |   10 +++++-----
     1 files changed, 5 insertions(+), 5 deletions(-)
    diff --git a/railties/environments/boot.rb b/railties/environments/boot.rb
    index cd21fb9..4bb0e06 100644
    --- a/railties/environments/boot.rb
    +++ b/railties/environments/boot.rb
    @@ -82,17 +82,17 @@ module Rails
           def load_rubygems
             require 'rubygems'
    -        unless rubygems_version >= '0.9.4'
    -          $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
    +        min_version = '1.1.1'
    +        unless rubygems_version >= min_version
    +          $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
               exit 1
           rescue LoadError
    -        $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again:
    +        $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again:
             exit 1
  • Jeremy Kemper

    Jeremy Kemper July 9th, 2008 @ 07:04 AM

    • Milestone set to 2.1.1
    • Assigned user set to “Rick”
    • State changed from “new” to “open”
  • Clemens Kofler

    Clemens Kofler July 9th, 2008 @ 01:21 PM


    I had that problem as well a few days ago.

    Question: Would it be possible to have something similar to rake gems:install for RubyGems itself? And would that make sense?

  • Jeremy Kemper

    Jeremy Kemper July 16th, 2008 @ 12:35 AM

    The initializer could do a stricter version check. Then boot.rb doesn't have to be updated for all apps (the rubygems version requirement in boot.rb is just enough to get Rails off the ground).

  • Jeremy Kemper

    Jeremy Kemper July 16th, 2008 @ 01:07 AM

    • State changed from “open” to “committed”


  • Ben Oakes

    Ben Oakes July 16th, 2008 @ 05:02 AM

    Thanks, everyone, for your work on this. I really appreciate that this will save someone some grief down the road!

  • Steve Verlinden

    Steve Verlinden July 16th, 2008 @ 08:41 AM

    Thank you! I saw this error today on Linux (with RubyGems 0.9.4), this ticket really help me to quickly fix this.

  • David Lowenfels

    David Lowenfels July 16th, 2008 @ 09:48 AM

    @jeremy: any way you can edit the comments to remove my email address (spambait) from my "July 8th, 2008 @ 08:50 PM" comment? Thx!

  • Glenn Powell

    Glenn Powell August 6th, 2008 @ 04:11 PM

    I'm not sure if my problem is related to (or caused by) this fix, but now for some reason when I run any script/generate call, I get undefined method errors spawning from the lib files that I require in my environment.rb file.

    For instance I have these lines in my environment.rb:

    1. Bootstrap the Rails environment, frameworks, and default configuration

    require File.join(File.dirname(__FILE__), 'boot')

    require 'locale/custom'

    So when the I call 'ruby script/generate mailer postoffice', the process loads my environment.rb (apparently before loading the rest of Rails core). Because when it gets to my custom require, it fails saying it can't find the Rails core modules and classes referenced in the required file. Specifically: 'backend=' for I18n:Module.

    Why wouldn't it have loaded the Rails core files at this point? And why does the script/server call work just fine?

  • Ryan Bigg

    Ryan Bigg October 9th, 2010 @ 10:11 PM

    • Tag cleared.

    Automatic cleanup of spam.

  • Jeff Kreeftmeijer
  • bingbing

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>