132

I'm running a Rails 2.3.5 application and upon running script/server I am shown the following:

./script/../config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path': undefined method `source_index' for Gem:Module (NoMethodError)
    from ./script/../config/boot.rb:60:in `load_initializer'
    from ./script/../config/boot.rb:44:in `run'
    from ./script/../config/boot.rb:17:in `boot!'
    from ./script/../config/boot.rb:123
    from script/server:2:in `require'
    from script/server:2

If I comment out line 60 in boot.rb (Rails::GemDependency.add_frozen_gem_path) and run script/server, I get this:

=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
./script/../config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path': undefined method `source_index' for Gem:Module (NoMethodError)
    from ./script/../config/../vendor/rails/railties/lib/initializer.rb:298:in `add_gem_load_paths'
    from ./script/../config/../vendor/rails/railties/lib/initializer.rb:132:in `process'
    from ./script/../config/../vendor/rails/railties/lib/initializer.rb:113:in `send'
    from ./script/../config/../vendor/rails/railties/lib/initializer.rb:113:in `run'
    from /home/developer/bigpink/config/environment.rb:13
    from /home/developer/bigpink/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
    from /home/developer/bigpink/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
    from /home/developer/bigpink/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
    from /home/developer/bigpink/vendor/rails/activesupport/lib/active_support/dependencies.rb:156:in `require'
    from /home/developer/bigpink/vendor/rails/railties/lib/commands/server.rb:84
    from script/server:3:in `require'
    from script/server:3

So, not really sure what to do. Hoping I can get some quick help. Thanks!

noodleboy347
  • 1,355
  • 2
  • 9
  • 8

5 Answers5

297

I just ran into this problem myself while trying to upgrade an older Rails app from REE 1.8.7 to 1.9.3-p385. Oddly, Ruby 1.9.3-p327 works just fine. What it came down to was ruby-1.9.3-p385 had installed RubyGems version 2.0.2 for me, and 1.9.3-p327 has RubyGems v1.8.23 installed.

Gem.source_index has been deprecated for a while, but since Rails 2.3 is not getting any updates except critical security patches, this will never get fixed. RubyGems v2.0 finally removed that method. Downgrade to any rubygems version prior to 2.0.0, like 1.8.25 to get the functionality back for now. You can get a compatible version using gem update --system 1.8.25.

As a very important aside, Rails 2.3.5 needs to be updated to a minimum of 2.3.17. There are critical security vulnerabilities that open you up to some very nasty attacks. In the long term, upgrading to 3.x needs to be considered a very strong need.

Brad Werth
  • 17,411
  • 10
  • 63
  • 88
uxp
  • 3,209
  • 1
  • 15
  • 16
  • Thank you so much! It worked perfectly. And yes, thanks, I am in the midst of upgrading to 2.3.17, and then to the latest 3.x. – noodleboy347 Mar 12 '13 at 21:38
  • @uxp Any tips for this issue: http://stackoverflow.com/questions/15374188/why-is-my-rake-call-causing-an-undefined-method-source-index-error/15378764 – Evolve Mar 13 '13 at 07:03
  • Thank you. I also ran into this problem upgrading from 1.8.7 to 1.9.3-p385 – mkelley33 Mar 23 '13 at 00:42
  • Thank you so much. I ran into the same problem with our Redmine installation. – Bryan CS Aug 20 '13 at 16:23
  • 88
    Anyone using [RVM](http://rvm.io/) can call `rvm rubygems latest-1.8` to downgrade rubygems and fix this issue. – martin Sep 13 '13 at 10:12
  • 1
    Martin's comment (Anyone using RVM can call rvm rubygems latest-1.8 to downgrade rubygems and fix this issue. ) helped me resolve my issue, where I was stuck since few hours. Thanks a lot. – Prajkta P Jan 31 '14 at 06:31
  • 32
    Need to force downgrading rubygems: `rvm rubygems --force latest-1.8` – Matt White May 03 '14 at 13:47
  • damn, downgrading rubygems for rvm, that's inconvenient, is't it.. guess that Rails 2 is just as good as dead. – Ondřej Želazko Oct 01 '14 at 09:35
32

for rvm users,

rvm install rubygems 1.8.2 --force
Arivarasan L
  • 9,538
  • 2
  • 37
  • 47
  • 1
    I had to go back to 1.6.2 to make this work. But it was this command that was needed. – Zane Feb 28 '15 at 22:50
26

This helped me: http://djellemah.com/blog/2013/02/27/rails-23-with-ruby-20/

I did this in combination with gem update --system 1.8.25, which might not be needed for your case.

iblue
  • 29,609
  • 19
  • 89
  • 128
ippa
  • 361
  • 2
  • 2
1

Another way to do this is to install slimgems: gem install slimgems. This is a drop-in fork of RubyGems that works better with old versions.

johnnyb
  • 622
  • 5
  • 17
0

Update: In addition to the @uxp answer, if you running this command on a Mac running Catalina, there is a small change in command, you need to add -n.

So the command would be sudo gem update --system -n 1.8.25

NadZ
  • 1,024
  • 9
  • 10