已经激活的rake版本与Gemfile所需的版本不同,可以防止rake命令

Aar*_*ron 35 rake gem ruby-on-rails

这是我的错误:

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)
Run Code Online (Sandbox Code Playgroud)

我不能运行任何rake任务,这似乎是我所有其他问题的根源.几天前,当我运行rake命令时,情况并非如此.任何人都可以解释这里发生了什么,以及如何让我的应用回到正轨?我撞墙了.此外,bundle exec并没有为我解决问题的根源.我过去从来没有这样做过,现在还没有工作.

man*_*9.d 36

编辑2: 你应该看一下bundle update并改变你的工作流程.请参阅此问题以获得进一步的帮助.


原始答案

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

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

我在这种情况下的解决方案就是删除,Gemfile.lock如果我不太担心其他宝石版本和他们无休止的依赖.否则,您可以尝试删除Gemfile.lock谈论rake版本的一行.奔跑bundle install,世界应该再次成为一个幸福的地方.(编辑2:运行bundle update --source而不是这个.不要这样做.)

PS:尝试使用gemsets并使用rvm为不同的项目组织你的宝石.

编辑

我现在更喜欢使用rbenv来管理安装,项目的所有gem都vendor/bundle使用bundle install --path选项.后来用每个gem命令调整范围bundle exec.

因此,rails s成为bundle exec rails s.在我看来,如果它意味着事情将保持清洁并且诸如此类之类的冲突不会发生,那么更多的打字就更好了.

  • Downvoting.你不应该通过删除或改变`Gemfile.lock`来破坏Bundler.相反,使用`bundle update`或其他东西. (3认同)

Ben*_*phy 31

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

$ gem install rubygems-bundler

$ gem regenerate_binstubs

然后再试一次你的耙子.

  • 赞美JEEZUZ感谢LAWD - 但我有一个问题:什么是实际问题 - 发生了什么 - 以及rubygems-bundler如何解决它? (5认同)

phi*_*oye 29

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

  • 这也解决了我的问题!我的问题是"你已经激活了rake 11.3.0,但你的Gemfile需要rake 11.2.2". (3认同)

Aba*_*say 21

我有一个类似的问题,我对从我的线上删除一条线表示怀疑Gemfile.lock,这似乎是hacky,并且前置bundle exec每个rake命令的不便也不是一个选项.我通过首先进入我的问题Gemfile.lock来解决这个问题,看看rake那里有什么版本(在我的例子中是11.1.2).我的想法是卸载rake并安装此版本.Running gem uninstall rake给出了这个输出:

选择要卸载的gem:

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

我卸载了两个rake-11.2.2rake-11.3.0.这解决了我的问题

  • 这是完美的..简单,容易,有意义! (2认同)

Ish*_*eet 5

用这个:

gem install rake -v "version-you-want"
Run Code Online (Sandbox Code Playgroud)

  • 辉煌。该命令解决了该问题。我没有运气尝试过上面的那些。谢谢 (2认同)