Loading environment fails with an outdated version of RubyGems while using config.gem "some_gem"
Reported by Ben Oakes | June 20th, 2008 @ 09:32 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:
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
Comments and changes to this ticket
-

jeff June 26th, 2008 @ 04:57 PM
- → Tag changed from to 2.1
+1
it would be nice to have some kind of warning or failure if rails is incompatible with gem version < x
-
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 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 July 9th, 2008 @ 02:50 AM
- no changes were found...
-
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 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 -
Jeremy Kemper July 9th, 2008 @ 07:04 AM
- → Milestone changed from to 2.1.1
- → State changed from new to open
- → Assigned user changed from to rick
-
Clemens Kofler July 9th, 2008 @ 01:21 PM
+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?
-
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).
-
-

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 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 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 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:
- 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?
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Source available from github
Repository is at http://github.com/rails/rails
Check out the development master (Edge Rails):
git clone git://github.com/rails/rails.git
Creating or reviewing a patch
See the contributor guide.
Creating a feature request
Please don't. If you want a new feature in Rails, you'll have to pull up your sleeves and get busy yourself. Or convince someone else to do it. See the contributor guide on how to get going. But posting them here is just going to lead to ticket root.
Creating a bug report
When creating a bug report, be sure to include as much relevant information as possible. Post the code sample that causes the problem. Preferably, alter the unit tests and show through either changed or added tests how the expected behavior is not occuring.
Security vulnerabilities should be reported via an email to security@rubyonrails.org, do not use trac for reporting security vulnerabilities. All content in trac is publicly available as soon as it is posted.
Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kinda bug, you're creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to sign on to with a "I'm having this problem too"..
