Rails: You have already activated rake 10.3.1, but your Gemfile requires rake 10.2.2 (Gem::LoadError)

后端 未结 15 1770
自闭症患者
自闭症患者 2020-12-05 02:21

Here is my error:

rake aborted!
Gem::LoadError: You have already activated rake 10.3.1, but your Gemfile requires rake 10.2.2. Prepending `bundle exec` to yo         


        
相关标签:
15条回答
  • 2020-12-05 02:24

    EDIT 2: You should look at bundle update and change your workflow a little. Refer to this question for further assistance.


    Original answer

    This is a simple issue which happens when your gemset has a rake version that is newer than the version number your Gemfile.lock mentions.

    As is mentioned in the error message, you can use bundle exec to get things working.

    My solution in such cases is to just remove Gemfile.lock if I am not too worried other gem versions and their endless dependencies. Otherwise, you can try just removing the one line in Gemfile.lock which talks about the version of rake. run bundle install and the world should be a happy place again. (edit 2: Run bundle update --source instead of this. Don't do this.)

    PS: Try using gemsets and organising your gems with rvm for different projects.

    Edit

    I prefer using rbenv now for managing installations and all gems for a project reside in vendor/bundle using bundle install --path option. Later scope every gem command with bundle exec.

    Hence, rails s becomes bundle exec rails s. A little more typing is, in my opinion, better if it means that things will remain clean and conflicts such as this one don't happen.

    0 讨论(0)
  • 2020-12-05 02:26

    Use this:

    gem install rake -v "version-you-want"
    
    0 讨论(0)
  • 2020-12-05 02:27

    A simple solution that worked for me is to simply run bundle update rake.

    0 讨论(0)
  • 2020-12-05 02:33

    For Rails version 5 or 6, try to use "rails" command:

    rails db:migrate 
    

    without errors.

    0 讨论(0)
  • 2020-12-05 02:34

    I meet the similar problem. My solution is change the line of rake version "gem 'rake', '~> 10.3'" in file Gemfile, delete Gemfile.lock and run 'bundler install', the new Gemfile.lock will show the new version 10.3.1. Then everything will be fine.

    0 讨论(0)
  • 2020-12-05 02:36

    According to this solution (that worked for me) : https://stackoverflow.com/a/23668399/4260090

    You can solve it by using rubygems-bundler

    Type these commands in your terminal :

    $ gem install rubygems-bundler
    $ gem regenerate_binstubs
    

    It should work now

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