Passenger can’t find Rails

If you are running in to an issue where you are trying to get a Rails app up and running, but are receiving the error “Missing the Rails 2.x.x gem…” when you attempt to access it despite Rails being installed and available to your system, do not panic.  Rails is just giving you an extremely unhelpful error message.

Rails catches *any* problem loading the Rails gem, and then responds with that error.

 rescue Gem::LoadError => load_error
      $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
      exit 1

If you inspect load_error from the line above, you should see the actual error message. In my case it was that ActiveSupport required Rack v1.0.0, but Passenger had already instantiated Rack v1.1.0. This led to a failure when loading the Rails gem, which was of course incorrectly reported. My quick solution was to uninstall the new version of rack, and force the install of the older version.

As a side note: I have the world’s worst code highlighter.

Leave a Reply

Your email address will not be published. Required fields are marked *

8 Comments

  1. Throlkim

    Phew, thanks for that – had exactly the same problem. That saved me a headache. 🙂

  2. Soup

    This is very good information.

  3. Mattias Arro

    Thanks man, you saved my day!

  4. MiddleEarther

    I spent a good part of a day reading google posts before I gave up on this… came back to it and your post fixed it. I went and added a line to the boot.rb prior to the complaint about failing to load the gem:

    $stderr.puts “Actual load error: ” + load_error

    I really don’t see why rails would ever purposefully obscure the real error – sounds like a mistake.

  5. walmsul

    I reiterate all previous comments… this saved me a ton of time!

    Thanks!

  6. Eric Pierce

    +1, I had the same issue. Thanks for sharing your solution!

  7. GConner

    Hi All, I have the same problem, and I’m hoping you can tell me what I’m missing. Here’s the backtrace, and I don’t see something obvious (other than it can’t find rails).

    Backtrace:
    # File Line Location
    0 /data/current_dpweb/config/boot.rb 67 in `exit’
    1 /data/current_dpweb/config/boot.rb 67 in `load_rails_gem’
    2 /data/current_dpweb/config/boot.rb 54 in `load_initializer’
    3 /data/current_dpweb/config/boot.rb 38 in `run’
    4 /data/current_dpweb/config/boot.rb 11 in `boot!’
    5 /data/current_dpweb/config/boot.rb 111
    6 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb 31 in `gem_original_require’
    7 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb 31 in `require’
    8 /data/current_dpweb/config/environment.rb 7
    9 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb 31 in `gem_original_require’
    10 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb 31 in `require’
    11 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/railz/application_spawner.rb 318 in `preload_application’
    12 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/railz/application_spawner.rb 267 in `initialize_server’
    13 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/utils.rb 323 in `report_app_init_status’
    14 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/railz/application_spawner.rb 246 in `initialize_server’
    15 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/abstract_server.rb 194 in `start_synchronously’
    16 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/abstract_server.rb 163 in `start’
    17 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/railz/application_spawner.rb 222 in `start’
    18 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/spawn_manager.rb 253 in `spawn_rails_application’
    19 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/abstract_server_collection.rb 126 in `lookup_or_add’
    20 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/spawn_manager.rb 247 in `spawn_rails_application’
    21 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/abstract_server_collection.rb 80 in `synchronize’
    22 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/abstract_server_collection.rb 79 in `synchronize’
    23 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/spawn_manager.rb 246 in `spawn_rails_application’
    24 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/spawn_manager.rb 145 in `spawn_application’
    25 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/spawn_manager.rb 278 in `handle_spawn_application’
    26 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/abstract_server.rb 352 in `__send__’
    27 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/abstract_server.rb 352 in `main_loop’
    28 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/lib/phusion_passenger/abstract_server.rb 196 in `start_synchronously’
    29 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/bin/passenger-spawn-server 61

  8. tib

    MiddleEarther :
    I spent a good part of a day reading google posts before I gave up on this… came back to it and your post fixed it. I went and added a line to the boot.rb prior to the complaint about failing to load the gem:
    $stderr.puts “Actual load error: ” + load_error
    I really don’t see why rails would ever purposefully obscure the real error – sounds like a mistake.

    thanks !
    and thanks for the author ! you saved my day !

    By the way, I’d like to congratulate the author of the original function, this is just magic ! ^^