Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Excessive warning output on environment load #24

stephencelis opened this Issue · 25 comments

Under RVM 1.9.1, whenever I require the bundler environment, errors paired with gemspecs continuously print out to stderr.

WARNING:  #<NoMethodError: undefined method `>' for nil:NilClass>
# -*- encoding: utf-8 -*-
(...gemspec prints here entirely...)
WARNING:  Invalid .gemspec format in \


At the end, I get a couple dozen warnings for "already initialized constant".

Hundreds of lines of output, in all (and all silenced when 2>/dev/null).

This has been occurring since Bundler 0.9.beta3 on Rails 3.0.pre and now Rails 3.0.0.beta with the latest Bundler 0.9.2. It occurs for script/{console,server} and bundle exec [ruby] script/{console,server} and bundle exec zsh; script/{console,server} all the same.


I'm having the same issue.


Same here with Ruby 1.9.1


I'm having this same issue


So, I have no idea what actually is causing it. I spent a large amount of time debugging it and it's somewhere in Gem::Specification#method_missing.

I'm worried that it's some ruby bug. If somebody can find the source and submit a patch, i would be greatly appreciative.


I see this issue on Windows using 1.9.1 but not on Ubuntu using 1.9.1. (I'm not using RVM currently on Ubuntu)


hmm, @specification_version is nil when we come to method_missing... why??


So I've been digging and I found that the "undefined method '>' for nil:NilClass" is thrown in site_ruby/1.9.1/rubygems/specification.rb method_missing (line 531) because @specification_version is nil. This exception is caught in source_index.rb line 107 which dumps the spec code. I was able to mute the exceptions there but the real question is why isn't @specification_version being set for the specs loaded by bundler. I hope this is helpful. Let me know if I can help in any way.


Just to clarify the environment, it occurs without rvm.

To reproduce the problem:

$ mv ~/.rvm ~/_rvm (if you have rvm installed)
(open a new shell if you've used rvm)
$ svn co RUBY-TRUNK
$ ./configure
$ make
$ sudo make install (if your shell requires)
$ rehash
$ which ruby
$ ruby -v
ruby 1.9.2dev (2010-02-06 trunk 26592) [x86_64-darwin10.2.0]
$ sudo gem install bundler
$ rehash (if your shell requires)
$ gem list

*** LOCAL GEMS ***

bundler (0.9.3)
minitest (1.5.0)
rake (0.8.7)
rdoc (2.2.2)
$ mkdir testapp
$ cd testapp
$ echo 'gem "rake"' > Gemfile
(fix cli.rb and add .to_s at the end)
$ sudo vi +103 /usr/local/lib/ruby/gems/1.9.1/gems/bundler-0.9.3/lib/bundler/cli.rb
$ bundle exec ruby -e 1

I changed line 1038 of ruby's 1.9.1/rubygems/specification.rb


1038: required_attribute :rubygems_version, Gem::RubyGemsVersion


1038: puts '%s:%d' % [ __FILE__, __LINE__ ]
1039: k = Gem::RubyGemsVersion
1040: puts '%s:%d' % [ __FILE__, __LINE__ ]
1041: required_attribute :rubygems_version, k
1042: puts '%s:%d' % [ __FILE__, __LINE__ ]

and run the auctual command invoked when one run 'bundle exec ruby -e 1'.

$ RUBYOPT="-I/PATH/TO/gems/bundler-0.9.3/lib -rbundler/setup -rubygems" ruby -e 1

and got

WARNING:  #' for nil:NilClass>
# -*- encoding: utf-8 -*-
WARNING:  Invalid .gemspec format in '/PATH/TO/specifications/rake-0.8.7.gemspec'

This means accessing constant Gem::RubyGemsVersion is the root of our problem, right? (autoload??)

din commented

I think that the error is in file "ruby/1.9.1/rubygems/source_index.rb", somewhere around line 109 of it.

Yep. Error is in this string:

 gemspec = eval spec_code, binding, file_name

Last backtrace line is:

 /var/opt/ruby/lib/ruby/1.9.1/rubygems/specification.rb:530:in `method_missing'

Error is because @specification_version is 'nil'

Full backtrace of error is:

"/var/opt/ruby/lib/ruby/1.9.1/rubygems/specification.rb:531:in `method_missing'",
 "/var/opt/ruby/lib/ruby/gems/1.9.1/specifications/mime-types-1.16.gemspec:4:in `block in load_specification'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems/specification.rb:421:in `initialize'",
 "/var/opt/ruby/lib/ruby/gems/1.9.1/specifications/mime-types-1.16.gemspec:3:in `new'",
 "/var/opt/ruby/lib/ruby/gems/1.9.1/specifications/mime-types-1.16.gemspec:3:in `load_specification'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems/source_index.rb:95:in `eval'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems/source_index.rb:95:in `load_specification'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems/source_index.rb:156:in `block (2 levels) in load_gems_in'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems/source_index.rb:155:in `each'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems/source_index.rb:155:in `block in load_gems_in'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems/source_index.rb:152:in `reverse_each'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems/source_index.rb:152:in `load_gems_in'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems/source_index.rb:348:in `refresh!'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems/source_index.rb:78:in `from_gems_in'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems/source_index.rb:58:in `from_installed_gems'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems.rb:913:in `source_index'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems/gem_path_searcher.rb:84:in `init_gemspecs'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems/gem_path_searcher.rb:19:in `initialize'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems.rb:871:in `new'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems.rb:871:in `block in searcher'",
 "<internal:prelude>:8:in `synchronize'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems.rb:870:in `searcher'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems.rb:528:in `find_files'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems.rb:1093:in `<top (required)>'",
 "<internal:gem_prelude>:161:in `require'",
 "<internal:gem_prelude>:161:in `load_full_rubygems_library'",
 "<internal:gem_prelude>:273:in `const_missing'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems/specification.rb:1038:in `<class:Specification>'",
 "/var/opt/ruby/lib/ruby/1.9.1/rubygems/specification.rb:28:in `<top (required)>'",
 "/var/opt/ruby/lib/ruby/gems/1.9.1/gems/bundler-0.9.2/lib/bundler/rubygems.rb:2:in `require'",
 "/var/opt/ruby/lib/ruby/gems/1.9.1/gems/bundler-0.9.2/lib/bundler/rubygems.rb:2:in `<top (required)>'",
 "/var/opt/ruby/lib/ruby/gems/1.9.1/gems/bundler-0.9.2/lib/bundler.rb:4:in `require'",
 "/var/opt/ruby/lib/ruby/gems/1.9.1/gems/bundler-0.9.2/lib/bundler.rb:4:in `<top (required)>'",
 "config/boot.rb:6:in `require'",
 "config/boot.rb:6:in `rescue in <main>'",
 "config/boot.rb:2:in `<main>'"

yeah, so investigating the mechanism that @specification remains nil.

din commented

I suppose that this issue isn't caused by Bundler, but by Rubygems.
I have Ruby HEAD (checked out from SVN and compiled by myself) and when I write in irb

 require "rubygems/specification"

It shows the same errors.


hmm, I'll report this to ruby's redmine.


thread from ruby-core:345886 discusses this...


Does following modification fix the problem?

At least, bundle exec ruby -e 1 succeeds.

  1. Edit lib/bundler.rb from
    4: require 'bundler/rubygems'
    4: require 'bundler/rubygems-ext'
  2. Edit lib/bundler/rubygem.rb from
    1: require 'rubygems'
    2: require 'rubygems/specification'
    1: unless defined? Gem
    2: require 'rubygems'
    3: require 'rubygems/specification'
    4: end
  3. Rename lib/bundler/rubygems.rb (Editted in 2.) to lib/bundler/rubygems-ext.rb. This rename is because gem_prelude.rb of ruby 1.9 has following code.
if /#{Regexp.escape File::SEPARATOR}rubygems\.rb\z/ =~ path
  raise LoadError, "another rubygems is already loaded from #{path}"

@sakuro: yes that fixed it for me.


I can confirm that it helps fixing the same issue in rails 3 too.


I've created a patch in my fork of bundler. Feel free to pull it in:


Applying the above fix from @sakura worked to remove the gem spec errors but I'm still getting the "already initialized constant" errors. My output is here: Thanks for the help


re: "already initialized constant" errors

as pointed out by Balazs Nagy the "warning: already initialized constant" comes from Ruby cruft. removing the old library directory and starting with a fresh install removes those warnings.

note, this does not fix the verbose "Invalid .gemspec format in" warnings.

here's approximately what I did on OS X (snow leopard).

gem list --no-version > gem_list.txt
sudo mv /usr/local/lib/ruby /usr/local/lib/ruby-old
# install
sudo su
gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n
gem install rails --pre
gem install sqlite3-ruby
env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
# install remaining gems

@trevor, Is there any way to install just the rubygems stuff? Your explanation makes it sound like it's a rubygems issue, not necessarily ruby itself. I'm running ruby 1.9.1 if that makes a difference.



from what i can tell ruby development has moved away from using the "site_ruby" directory. as i understand it "warning: already initialized constant" is happening because rubygems is being included twice.

in my problem-installation i can find rubygems in two separate places -


note they're not even the same files -

% diff -q /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb /usr/local/lib/ruby/1.9.1/rubygems.rb
Files /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb and /usr/local/lib/ruby/1.9.1/rubygems.rb differ

on a clean install from ruby development, after making sure the old /usr/local/lib/ruby is moved elsewhere, i only get one instance of rubygems -


to answer your question there's likely a way to do it without having to reinstall ruby, but this seemed like the easiest way.

@SamSaffron SamSaffron referenced this issue from a commit in SamSaffron/bundler
@ariejan ariejan Fixed name conflict with 'rubygems.rb'. Fixes #24 9fbab6d
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.