How to fix: undefined method `specifications' (caused by RubyGems 1.8)

Updated . Posted . Visible to the public.

Sometimes, when running a rake task, RubyGems 1.8.5 raises an error:

rake aborted!
undefined method `specifications' for "/usr/lib/ruby/gems/1.8":String

This has been fixed since May 31 but is still not available as a new RubyGems version.

Either wait for a new version to eventually come out, downgrade to some really old version (1.6.2 works for some) or apply the fix Show archive.org snapshot manually:

  • Find your rubygems.rb -- mine was located at /usr/local/lib/site_ruby/1.8/rubygems.rb
  • Modify the self.each_load_path method according to the path. Mine now looks like this:
    def self.each_load_path(partials)
    partials.each do |gp|
    base = File.basename gp
    specfn = File.join(dir, "specifications", "#{base}.gemspec")
    if File.exists? specfn
    spec = eval(File.read(specfn))
    spec.require_paths.each do |rp|
    yield File.join(gp,rp)
    end
    else
    filename = File.join(gp, 'lib')
    yield(filename) if File.exists? filename
    end
    end
    end
  • Also, I needed to change a second appearance of “gemdir.add(load_path).expand_path” in line 261 to “result << load_path” for it to work (which is probably covered by some other fix commit).

I bet there is a semi-automated way to get a patch from the Github repository that you can apply on your rubygems.rb but I don't care enough to toy around with git format-patch. If you do, let me know.

Arne Hartherz
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2011-06-28 14:46)