Already activated rake version different than what

2019-01-13 20:46发布

问题:

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 your command may solve this.
/Users/AaronWilliamson/.gem/ruby/2.1.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:34:in `block in setup'
/Users/AaronWilliamson/.gem/ruby/2.1.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:19:in `setup'
/Users/AaronWilliamson/.gem/ruby/2.1.0/gems/bundler-1.5.3/lib/bundler.rb:119:in `setup'
/Users/AaronWilliamson/.gem/ruby/2.1.0/gems/bundler-1.5.3/lib/bundler/setup.rb:7:in `<top (required)>'
/Users/AaronWilliamson/Desktop/Ripelist-Classifieds/config/boot.rb:4:in `<top (required)>'
/Users/AaronWilliamson/Desktop/Ripelist-Classifieds/config/application.rb:1:in `<top (required)>'
/Users/AaronWilliamson/Desktop/Ripelist-Classifieds/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- bundler/setup
/Users/AaronWilliamson/Desktop/Ripelist-Classifieds/config/boot.rb:4:in `<top (required)>'
/Users/AaronWilliamson/Desktop/Ripelist-Classifieds/config/application.rb:1:in `<top (required)>'
/Users/AaronWilliamson/Desktop/Ripelist-Classifieds/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

I can't run any rake tasks and this seems to be the root of all my other problems. It wasn't like this a couple days ago when I was running rake commands. Can anyone explain what's going on here and how to get my app back on track? I've hit a wall. Also, bundle exec doesn't fix the root of the problem for me. I never had to do that in the past and it's still not working now.

回答1:

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.



回答2:

You can use rubygems-bundler to solve this. Run the following commands:

$ gem install rubygems-bundler

$ gem regenerate_binstubs

Then try your rake again.



回答3:

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



回答4:

I had a similar issue and I was skeptical about removing a line from my Gemfile.lock, it seemed hacky and the inconvenience of prepend bundle exec to every rake command was not an option either. I fixed this by first going into my Gemfile.lock to see what version of rake was there (in my case it was 11.1.2). My thought was to uninstall rake and install this version. Running gem uninstall rake gave this output:

Select gem to uninstall:

  1. rake-10.5.0
  2. rake-11.1.1
  3. rake-11.1.2
  4. rake-11.2.2
  5. rake-11.3.0
  6. All versions

I uninstalled both rake-11.2.2 and rake-11.3.0. That fixed my problem



回答5:

Use this:

gem install rake -v "version-you-want"


回答6:

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



回答7:

Type this command:

bundle update rake


回答8:

I tried another way which is delete Gemfile.lock then run bundle install. After that I run rake db:migrate. And everything works fine.

Although I don't think remove Gemfile.lock is bad practice, but may be; who know.



回答9:

As mentioned on earlier answers 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.

The easiest way to debug this is to run bundle update.

The other ways could be to remove Gemfile.lock and running bundle install or simply deleting the line in Gemfile.lock that corresponds to the rake version and try bundle install. But this might sometimes corrupt the Gemfile. I would prefer the first method because it is the safest and the easiest.



回答10:

Go in the Gemfile.lock, find the rake file and update the version there.

I got this error:

Gem::LoadError: You have already activated rake 11.2.2, but your Gemfile requires rake 11.1.2. Prepending bundle exec to your command may solve this.

What I did was to change the version of rake in the Gemfile.lock from: rake (11.1.2) to rake (11.2.2).

Everything worked fine after that.



回答11:

I had the same error:

You have already activated rake 12.0.0, but your Gemfile requires rake 11.3.0. Prepending "bundle exec" to your command may solve this.

I solved it by running bundle update

this updated the rake version to my activated rake version and everything worked I hope that works for you!



回答12:

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.



回答13:

bundle update rake works for me as well.

My error was Gem::LoadError: You have already activated rake 12.3.1, but your Gemfile requires rake 12.3.0. Prependingbundle execto your command may solve this.