24

I'm trying to run a Ruby on Rails app on a Dreamhost shared server. All is well so far except one weird bug I have not been able to unravel.

Sometimes when I visit the web app, I get presented with a Phusion Passenger error saying,

You have already activated rack 1.2.1, but your Gemfile requires rack 1.2.2. Consider using bundle exec.

When I just refresh the page it seems to work, though - no more Phusion Passenger error message.

Following other stack overflow threads and a similar Dreamhost wiki, I added the following to the top of the config/environment.rb file:

if ENV['RAILS_ENV'] == 'production'  # don't bother on dev
  ENV['GEM_PATH'] = '/home/myusername/.gems' + ':/usr/lib/ruby/gems/1.8'
end

enter image description here

aren55555
  • 1,677
  • 1
  • 20
  • 34

10 Answers10

9

try to restart your server after edit in your Gemfile and put this: gem 'rack', '1.2.1'

Surya
  • 15,703
  • 3
  • 51
  • 74
  • When I do a `bundle install` on the production server, I get the following: `You have requested: rack = 1.2.1 The bundle currently has rack locked at 1.2.2. Try running 'bundle update rack'` So I ran the command `bundle update rack`, everything updated successfully I think. The problem with this error is it takes some time to reproduce (I know its weird) - I will get back to you to verify whether or not this is the solution. – aren55555 Apr 26 '11 at 01:52
  • delete `Femfile.lock` and then try `bundle install`. Cause Gemfile.lock has the information of gem and their version currently used for your rails application, which gets generated by first your bundle command. – Surya Apr 26 '11 at 04:09
8

This works in Rails 3.0.x & Passenger 3.0.15

create a file:

config/setup_load_paths.rb

with content:

require 'rubygems'
require 'bundler/setup'

Passenger will then load the rack gem specified in your Gemfile.lock

t_itchy
  • 471
  • 4
  • 7
  • 1
    +1 I believe this is the correct answer (see [Passenger doc](http://modrails.com/documentation/Users%20guide%20Apache.html#bundler_support)). I figured this out myself by reading `lib/phusion_passenger/utils.rb` but later forgot it when I ran into the problem again. Thanks for the reminder. This method is especially effective when you're forced to run apps on different rack versions. – Kelvin Mar 03 '13 at 03:40
5

After long periods of inactivity, I've been receiving a similar error for a couple of Sinatra applications on a DreamHost VPS:

Phusion Passenger Error: You have activated rack 1.2.1, but your Gemfile requires rack 1.3.0.

Like how @aren55555 described, if you simply refresh the page, the error goes away. Here is something that I discovered about the server configuration:

[psXXXXX]$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.6
  - RUBY VERSION: 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/XXXXXXXXX/.gems/
  - RUBY EXECUTABLE: /usr/bin/ruby1.8
  - EXECUTABLE DIRECTORY: /home/XXXXXXXXX/.gems/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/XXXXXXXXX/.gems/               <-- Rack 1.3.0 Gem was installed here
     - /usr/lib/ruby/gems/1.8               <-- Rack 1.2.1 Gem was installed here
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

My guess as to what was happening is, after Passenger "wakes up", for some reason it's looking first (or perhaps only) to the Gems at the system-level, selecting Rack 1.2.1 as the latest version. My short-term hacky solution was simply to install Rack 1.3.0 there:

gem install rack -v 1.3.0 --install-dir /usr/lib/ruby/gems/1.8

It seems to have worked. Hope this is helpful to anyone else tearing their hair out there.

Todd Mazierski
  • 1,487
  • 1
  • 12
  • 7
5

I have the same issue: "You have already activated rack 1.2.1, but your Gemfile requires rack 1.2.3"

  1. Add to Gemfile: gem 'rack', '1.2.1'
  2. bundle update
  3. uninstall rack versions > 1.2.1

    [wasp]$ gem list |grep rack

    rack (1.2.1, 1.1.0, 1.0.1, 1.0.0)

  4. touch tmp/restart.txt

  5. :) happy
3

I ran into this with strscan, i.e., most recently, You have already activated strscan 3.0.3, but your Gemfile requires strscan 3.0.4. (This happened multiple times because strscan is a dependency of net-imap, which is a dependency of actionmailer, so regular Rails updates were causing new instances of this problem.)

Manually running gem install strscan fixes this, but I wanted a more permament fix, i.e. not manually running this every time strscan gets updated.

For me, in August 2022, it did not help to create config/setup_load_paths.rb as mentioned in another answer.

I found the permanent fix I wanted at https://github.com/phusion/passenger/issues/2409#issuecomment-1009548218, which was to add the following to my Nginx configuration:

server {
  ...
  passenger_env_var RUBYOPT '-r bundler/setup';
  ...
}

Now the Passenger Ruby process loads the correct verson every time.

richardkmiller
  • 2,902
  • 3
  • 31
  • 29
3

I solved this way on Dreamhost:

Remove from Gemfile any line: gem 'rack', ....

rm Gemfile.lock
rm -rf .bundle
rm -rf  vendor/bundle

install / use the gems locally and regenerates the file 'Gemfile.lock' with:

bundle install

install gems in vendor/bundle

bundle install --deployment

restart:

touch tmp/restart.txt
Sebtm
  • 7,002
  • 8
  • 29
  • 32
2

I just ran into this problem on Dreamhost. The problem is that the Dreamhost server has rack 1.2.1 installed and your Gemfile is loading 1.2.2. I found that if I just install rack:

gem install rack

Then the latest version of rack (1.2.2 as of right now) will get installed to your home gems folder (~/.gems). When passenger starts up, it will use 1.2.2.

Jason L
  • 133
  • 3
2

My had a similar problem with Apache: "You have already activated rack 1.2.3, but your Gemfile requires rack 1.2.2. Consider using bundle exec."

The problem was that Passenger install rack 1.2.3 and my rails APP rack 1.2.2:

$ gem list |grep rack
rack (1.2.2, 1.2.3)

Try:

$ gem uninstall --version=1.2.3 rack

restart the server and solved

salidux
  • 616
  • 6
  • 3
1

I fought with this problem for hours before eventually giving up on Passenger. Any new version of Rails will use a more recent Rack than Dreamhost's Passenger requires.

However, you don't need Passenger to boot the app. Dreamhost provides some pretty easy (and working) instructions about how to boot the app using FastCGI, and you won't have to corrupt your Gemfile in the process:

http://wiki.dreamhost.com/Rails_3#Using_FastCGI

KurtPreston
  • 1,062
  • 14
  • 28
0

It might be worth checking this out. Someone made a way to get debugger working with Passenger & Rails 3 - http://duckpunching.com/passenger-mod_rails-for-development-now-with-debugger

Marc
  • 2,584
  • 5
  • 33
  • 47