How to force rack to work around the usual “You have already activated rack…” bug?

后端 未结 6 1761
日久生厌
日久生厌 2021-01-01 11:21

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条回答
  • 2021-01-01 11:39

    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.

    0 讨论(0)
  • 2021-01-01 11:41

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

    0 讨论(0)
  • 2021-01-01 11:50

    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
    
    0 讨论(0)
  • 2021-01-01 11:59

    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.

    0 讨论(0)
  • 2021-01-01 11:59

    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.

    0 讨论(0)
  • 2021-01-01 12:05

    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.

    0 讨论(0)
提交回复
热议问题