Search code examples
ruby-on-railsrack

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?


Solution

  • 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.