How to force rack to work around the usual "You have already activated rack..." bug?

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?


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.

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.

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.

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

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.

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

Need Your Help

Many to Many Relationships not saving

entity-framework many-to-many

I have two entities with a fairly standard Many to Many relationship that I created in EF 5 Code First. These are Service and ServiceItem. The Service entity contains a collection of ServiceItems...

ASP.NET MVC 3 - posting complex JSON model to action json

I am trying to post the following JSON data to an Action method on my controller...