Ruby-on-rails Rails:您已经激活了 rake 10.3.1,但是您的 Gemfile 需要 rake 10.2.2 (Gem::LoadError)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23287357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:34:29  来源:igfitidea点击:

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

ruby-on-railsrubygemsrake

提问by Aaron

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 execdoesn'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.

我无法运行任何 rake 任务,这似乎是我所有其他问题的根源。几天前当我运行 rake 命令时不是这样的。谁能解释这里发生了什么以及如何让我的应用回到正轨?我撞墙了。此外,bundle exec不能为我解决问题的根源。过去我从来不需要这样做,现在它仍然不起作用。

采纳答案by manu29.d

EDIT 2:You should look at bundle updateand change your workflow a little. Refer to this questionfor further assistance.

编辑 2:您应该查看bundle update并稍微更改您的工作流程。请参阅此问题以获得进一步帮助。



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

这是一个简单的问题,当您的 gemset 的 rake 版本比您Gemfile.lock提到的版本号更新时会发生。

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

正如错误消息中提到的,您可以使用它bundle exec来使事情正常工作。

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

在这种情况下,我的解决方案是,Gemfile.lock如果我不太担心其他 gem 版本及其无穷无尽的依赖关系,则只需删除即可。否则,您可以尝试仅删除Gemfile.lock讨论 rake 版本的一行。奔跑吧bundle install,世界应该又是一个快乐的地方。(编辑2:运行bundle update --source而不是这个。不要这样做。)

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

PS:尝试使用gemsets 并使用 rvm为不同的项目组织您的 gem

Edit

编辑

I prefer using rbenvnow for managing installations and all gems for a project reside in vendor/bundleusing bundle install --pathoption. Later scope every gem command with bundle exec.

我现在更喜欢使用rbenv来管理安装,并且项目的所有 gem 都驻留在vendor/bundleusingbundle install --path选项中。稍后使用bundle exec.

Hence, rails sbecomes 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.

因此,rails s变成bundle exec rails s。在我看来,多一点打字会更好,如果这意味着事情会保持干净并且不会发生这样的冲突。

回答by Benjamin Dunphy

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

你可以用它rubygems-bundler来解决这个问题。运行以下命令:

$ gem install rubygems-bundler

$ gem regenerate_binstubs

$ gem install rubygems-bundler

$ gem regenerate_binstubs

Then try your rake again.

然后再试试你的耙子。

回答by philoye

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

一个对我有用的简单解决方案是简单地运行bundle update rake.

回答by Abass Sesay

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 execto every rake command was not an option either. I fixed this by first going into my Gemfile.lockto see what version of rakewas there (in my case it was 11.1.2). My thought was to uninstall rakeand install this version. Running gem uninstall rakegave this output:

我有一个类似的问题,我是持怀疑态度,从我删除线Gemfile.lock,似乎哈克和前插的不便bundle exec到每一个rake命令是不是一种选择,无论是。我通过首先进入我Gemfile.lock的查看版本来解决rake这个问题(在我的情况下它是 11.1.2)。我的想法是卸载rake并安装此版本。运行gem uninstall rake给出了这个输出:

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

选择 gem 卸载:

  1. rake-10.5.0
  2. rake-11.1.1
  3. 耙子-11.1.2
  4. 耙子-11.2.2
  5. rake-11.3.0
  6. 所有版本

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

我卸载了rake-11.2.2rake-11.3.0。那解决了我的问题

回答by Ishpreet

Use this:

用这个:

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

回答by Emmanuel Derozin

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

根据这个解决方案(对我有用):https: //stackoverflow.com/a/23668399/4260090

You can solve it by using rubygems-bundler

您可以通过使用解决它 rubygems-bundler

Type these commands in your terminal :

在终端中键入这些命令:

$ gem install rubygems-bundler
$ gem regenerate_binstubs

It should work now

现在应该可以使用了

回答by Serj Petrenko

Try to install nodejs, this was solved my problem.

尝试安装 nodejs,这解决了我的问题。

If you're on ubuntu run this command.

如果你在 ubuntu 上运行这个命令。

sudo apt-get install nodejs

回答by TorvaldsDB

My error message:

我的错误信息:

~ $ rake db:migrate                                                                                                                                                                            [2.6.5][10:21:00]
rake aborted!
Gem::LoadError: You have already activated rake 12.3.2, but your Gemfile requires rake 13.0.1. Prepending `bundle exec` to your command may solve this.
/Users/torvalds/workspace/ekohe/whitespace/config/boot.rb:5:in `<top (required)>'
/Users/torvalds/workspace/ekohe/whitespace/config/application.rb:3:in `require_relative'
/Users/torvalds/workspace/ekohe/whitespace/config/application.rb:3:in `<top (required)>'
/Users/torvalds/workspace/ekohe/whitespace/Rakefile:6:in `require_relative'
/Users/torvalds/workspace/ekohe/whitespace/Rakefile:6:in `<top (required)>'
(See full trace by running task with --trace)

I am using the rbenvto manage my Ruby environment.

我正在使用rbenv来管理我的 Ruby 环境。

My global Ruby version is as know as the defaultRuby version is 2.7.1, because I set it as rbenv global 2.7.1. However, my rake under Ruby 2.7.1 is 12.3.2

我的全局 Ruby 版本与defaultRuby 版本一样广为人知2.7.1,因为我将其设置为rbenv global 2.7.1. 但是,我在 Ruby 2.7.1 下的佣金是12.3.2

~ $ rake --version

rake, version 12.3.2

My project Ruby version is 2.6.5. however, my rake under Ruby 2.6.5 in my project is 13.0.1

我的项目 Ruby 版本是2.6.5. 但是,我的项目中 Ruby 2.6.5 下的佣金是13.0.1

~ $ bundle exec rake --version

rake, version 13.0.1

so I have to uninstall global rake

所以我必须卸载 global rake

~ $ gem uninstall rake

and reinstall it back

然后重新安装

~ $ gem install rake

Fetching rake-13.0.1.gem
Successfully installed rake-13.0.1
1 gem installed

it works! ~~~

有用!~~~

I'm not sure whether it will have an influence on other projects. However, so far it works.

我不确定它是否会对其他项目产生影响。但是,到目前为止它有效。

回答by Promise Preston

I experienced this issue:

我遇到过这个问题:

Here's my solution:

这是我的解决方案

Solution 1:

解决方案1

This solution works a lot of the time, simply update the gem causing the issue, say the gem is rack

这个解决方案在很多时候都有效,只需更新导致问题的 gem,比如 gem 是 rack

bundle update rack

Solution 2:

解决方案2

In some cases Solution 1may not work, and you will need to edit your Gemfile.lockfile.

在某些情况下,解决方案 1可能不起作用,您需要编辑Gemfile.lock文件。

Simply, open your Gemfile.lockfile and then change the version to the update requested.

只需打开您的Gemfile.lock文件,然后将版本更改为请求的更新。

In my case, the gem was rack, I had rack 2.0.7defined in my Gemfile.lockfile, but my application required rack 2.1.2, I simply had to modify it to rack 2.1.2in the Gemfile.lockfile.

在我的情况下,gem 是rack,我已经rack 2.0.7在我的Gemfile.lock文件中定义了,但是我的应用程序需要rack 2.1.2,我只需要rack 2.1.2Gemfile.lock文件中修改它。

I then had to uninstall the previous version of rack which is rack 2.0.7

然后我不得不卸载以前版本的机架 rack 2.0.7

 gem uninstall rack -v 2.0.7

And finally installed the new gem in production

最后在生产中安装了新的 gem

bundle install --without development test

Solution 3:

解决方案3

In very rare cases Solution 1and Solution 2may not work, and you will need to edit your Gemfilebefore updating the gem.

在极少数情况下,解决方案 1解决方案 2可能不起作用,您需要Gemfile在更新 gem 之前编辑您的。

In my case, the gem was puma, I had puma ~> 3.11defined in my Gemfile, but my application required puma ~> 4.3.1. At this point running bundle update pumaand editing my Gemfile.lockfile didn't work, since puma ~> 3.11version specified in the Gemfile would not allow an update to puma ~> 4.3.1.

就我而言, gem 是puma,我已经puma ~> 3.11在我的 中定义Gemfile,但我的应用程序需要puma ~> 4.3.1. 此时运行bundle update puma和编辑我的Gemfile.lock文件不起作用,因为puma ~> 3.11Gemfile 中指定的版本不允许更新到puma ~> 4.3.1.

I simply had to change the version of puma in the Gemfile to puma ~> 4.3.1and then ran the command.

我只需将 Gemfile 中的 puma 版本更改为puma ~> 4.3.1,然后运行该命令。

bundle update puma

That's all.

就这样。

I hope this helps

我希望这有帮助

回答by rookie Hyman

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.

我遇到了类似的问题。我的解决方案是更改文件 Gemfile 中的 rake version "gem 'rake', '~> 10.3'" 行,删除 Gemfile.lock 并运行 'bundler install',新的 Gemfile.lock 将显示新版本 10.3.1。那么一切都会好起来的。