title: "uninitialized constant Gem" or "Rails" when starting Rails 2 app
body: <p>I have an application using Rails 2.3.4 which I'm trying to run.  No matter how I start it, by using script/console or script/ferret_server, it always boils down to the same error:</p>
  
  <p>uninitialized constant Gem</p>
  
  <p>When I search online, I only find people who has a similar problem finding something inside of the Gem class.  But in my case, Gem is just not there at all.</p>
  
  <p>I am running Ruby on Ubuntu.  I tried using the version of Ruby that came with APT and a more recent one with RVM.  Nothing helped.</p>
  
  <p>Any idea how what can be causing thing and how to fix it?  Thanks in advance!</p>
  
  <p>Some extra details, as requested by commenters:</p>
  
  <p>Output of <code>ruby -v</code>:</p>
  
  <p><code>ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.03</code></p>
  
  <p>Output of <code>gem -v</code>:</p>
  
  <p><code>1.8.6</code></p>
  
  <p>Calling <code>ruby script/console</code> outputs a similar error (edited):</p>
  
  <pre>
  Loading development environment (Rails 2.3.4)
  /var/www/sites/example.com/releases/20110726061310/config/environment.rb:12:NameError: uninitialized constant Gem
  /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:254:in `require': no such file to load -- console_app (LoadError)
          from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:254:in `load_modules'
          from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:252:in `each'
          from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:252:in `load_modules'
          from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:21:in `setup'
          from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb.rb:54:in `start'
          from /usr/local/rvm/rubies/ree-1.8.7-2011.03/bin/irb:17
  </pre>
  
  <p>I'm trying to call Ferret Server to allow Passenger to connect to it, with the command:</p>
  
  <p><code>ruby --debug script/ferret_server -e production start</code></p>
  
  <p>Outputs the following error:</p>
  
  <pre>
  Exception `NameError' at ./script/../vendor/plugins/acts_as_ferret/lib/../../../../config/environment.rb:12 - uninitialized constant Gem
  uninitialized constant Gem
  </pre>
  
  <p>Alternatively, calling <code>bundle exec ruby --debug script/ferret_server -e production start</code> outputs the following error:</p>
  
  <p><code>superclass mismatch for class GemDependency</code></p>
  
  <p>Please note that I added the following right above the <code>Rails::Initializer.run do |config|</code> line in <code>config/environment.rb</code>:</p>
  
  <pre>
  require 'thread'
  if Gem::VERSION >= "1.3.6" 
    module Rails
      class GemDependency
        def requirement
          r = super
          (r == Gem::Requirement.default) ? nil : r
          end
        end
      end
    end
  require File.join(File.dirname(__FILE__), 'boot')
  </pre>
  
  <p>Remove the lines mentioned above gives <code>uninitialized constant Rails</code> errors instead.</p>