undefined method `source_index' for Gem:Module (NoMethodError)

Ruby on-RailsRuby on-Rails-2

Ruby on-Rails Problem Overview


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!

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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.

Solution 2 - Ruby on-Rails

for rvm users,

rvm install rubygems 1.8.2 --force

Solution 3 - Ruby on-Rails

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.

Solution 4 - Ruby on-Rails

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.

Solution 5 - Ruby on-Rails

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionnoodleboy347View Question on Stackoverflow
Solution 1 - Ruby on-RailsuxpView Answer on Stackoverflow
Solution 2 - Ruby on-RailsArivarasan LView Answer on Stackoverflow
Solution 3 - Ruby on-RailsippaView Answer on Stackoverflow
Solution 4 - Ruby on-RailsjohnnybView Answer on Stackoverflow
Solution 5 - Ruby on-RailsNadZView Answer on Stackoverflow