25

This is a common question, but none of the answers seem to solve the issue. I get the usual: You have already activated rack 1.4.1, but your Gemfile requires rack 1.3.6. Using bundle exec may solve this.

Clearing the Gemlock file did nothing and running bundle install again did nothing...running bundle install --binstubs did not solve the issue as "run ./bin/{rake|rails|etc} from your app root" just caused more errors. Is there a way to get rack around this apparently common problem?

fkoessler
  • 6,932
  • 11
  • 60
  • 92
user1149547
  • 349
  • 4
  • 10

6 Answers6

34

The problem is this:

  • You have (at least) two versions of Rack installed.

  • Your Gemfile calls for one version (1.3.6). Your current environment is providing another version (1.4.1).

  • By the time your application executes, the current environment has already loaded 1.4.1.

  • Bundler knows you need to load 1.3.6, but it can't load it. You may not load more than one version of the same gem, so the 1.4.1 version wins since it was loaded first.

  • Bundler complains to you.

Uninstall the problematic gems (e.g. gem uninstall rack -v 1.3.6). Even better, use RVM and gemsets to isolate your gems better and you won't encounter this issue.

John Feminella
  • 303,634
  • 46
  • 339
  • 357
  • Thank you for your well considered answer. However, I fixed it another way. I updated the site to Rails 3.2.1. Fortunately the rest of the site could take the update. – user1149547 Feb 11 '12 at 23:35
1

I had the same issue while trying to deploy a production app. I'm using rbenv to manage my ruby environments unicorn installed by default into rbenv. The gem dependencies listed in the Gemfile are being installed by bundler. It happens this was causing the issue.

The workaround I did was to uninstall unicorn from rbenv's environment and install it through the Gemfile. After all, I think this approach is more clean and straightforward.

If you are using RVM, the issue happens if you define a gem in the global environment that depends on rack the same way unicorn does and then define a per-project gemset. I think this is because of the dependencies of rails 3.1 (I'm not sure though). The solution is to uninstall unicorn (or the gem that installs rack 1.4.1) from global gemset and install it in a per-project gemset.

If you are using bundler and RVM you have two options: - create a gemset with rails and the gem that installs rack 1.4.1 (best suitable for dev workstations) - put the gem that depends on rack 1.4.1 in the Gemfile and let the bundler to the magic.

Tiago
  • 1,337
  • 11
  • 17
0

This problem is also common when you clone the project from a repository (ejem. github), because it might have the Gemsfile.lock already. So the gems it has might be different than the ones your enviroment has already loaded. So, firts get a backup of your Gemsfile.lock, then remove it and run bundle install --without production .It will install all your dependecies according with the GemFile. Be aware that if the application is old it might not work with the environment on your machine.

Aca
  • 25
  • 5
0

If the same error message concerning Spring brought you here, i.e. you're getting a message similar to this one:

You have already activated spring 1.4.0, but your Gemfile requires spring 1.3.6.

The solution is the same as the accepted answer:

gem uninstall spring -v 1.4.0
Jan Klimo
  • 4,643
  • 2
  • 36
  • 42
0

Sometimes all you need to do is just install the gem.

I had this problem on openshift and gone to the project dir:

$ rhc ssh APP_NAME

$ cd app-root

$ gem install GEM_NAME

after that the app started normally.

Community
  • 1
  • 1
Paulo Fidalgo
  • 21,709
  • 7
  • 99
  • 115
-1

Open Gemfile.lock, find the entry for rack (1.3.6) and delete it.

Undistraction
  • 42,754
  • 56
  • 195
  • 331