Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

This is not a public project

This project is archived and is in readonly mode.

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

#462

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:

REQUIRED_VERSION = '1.1.1'
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"
end

Reported by Ben Oakes · June 20th, 2008 @ 09:35 PM

State: committed
Milestone: 2.1.1
Assigned to: Rick Rick
Importance: none

Activity

  1. jeff
    jeff
    • Tag set to 2.1

    +1

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

    June 26th, 2008 @ 04:57 PM

  2. David Lowenfels
    David Lowenfels

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

    July 9th, 2008 @ 02:06 AM

  3. David Lowenfels
    David Lowenfels

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

    This patch makes it require rubygems >= 1.1.1

    July 9th, 2008 @ 02:46 AM

  4. David Lowenfels
  5. David Lowenfels
    David Lowenfels

    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
             end
     
           rescue LoadError
    -        $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
    +        $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
             exit 1
    
    

    July 16th, 2008 @ 11:00 AM

  6. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 2.1.1
    • Assigned user set to Rick
    • State changed from new to open

    July 9th, 2008 @ 07:04 AM

  7. Clemens Kofler
    Clemens Kofler

    +1

    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?

    July 9th, 2008 @ 01:21 PM

  8. Jeremy Kemper
    Jeremy Kemper

    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).

    July 16th, 2008 @ 12:35 AM

  9. Jeremy Kemper
    Jeremy Kemper
    • State changed from open to committed

    c7acfbb

    July 16th, 2008 @ 01:07 AM

  10. Ben Oakes
    Ben Oakes

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

    July 16th, 2008 @ 05:02 AM

  11. Steve Verlinden
    Steve Verlinden

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

    July 16th, 2008 @ 08:41 AM

  12. David Lowenfels
    David Lowenfels

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

    July 16th, 2008 @ 09:48 AM

  13. Glenn Powell
    Glenn Powell

    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?

    August 6th, 2008 @ 04:11 PM

  14. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 9th, 2010 @ 10:11 PM

  15. Jeff Kreeftmeijer
  16. bingbing