不起作用的Rake或其他Rake命令

14

嗨,我正在编写一些代码,并尝试

rake routes

出现了这个错误信息,但我不知道该怎么办

rake aborted!
Gem::LoadError: You have already activated rake 10.4.2, but your Gemfile requires rake 10.4.0. Prepending `bundle exec` to your command may solve this.

/home/simplybel/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.4/lib/bundler/runtime.rb:34:in `block in setup'
/home/simplybel/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.4/lib/bundler/runtime.rb:19:in `setup'
/home/simplybel/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.4/lib/bundler.rb:121:in `setup'
/home/simplybel/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.4/lib/bundler/setup.rb:7:in `<top (required)>'
/home/simplybel/projects/gamification/config/boot.rb:4:in `<top (required)>'
/home/simplybel/projects/gamification/config/application.rb:1:in `<top (required)>'
/home/simplybel/projects/gamification/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- bundler/setup
/home/simplybel/projects/gamification/config/boot.rb:4:in `<top (required)>'
/home/simplybel/projects/gamification/config/application.rb:1:in `<top (required)>'
/home/simplybel/projects/gamification/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
任何关于这个的帮助都将不胜感激。

2
我也遇到了这个问题,加上 bundle exec 也没有解决。 - Eric
@GitaarLAB 这个错误信息其实并不是很有用。因为rake没有在gem文件中,所以你不能仅仅通过更新版本来解决问题。而且在每个命令前都加上bundle exec也不是最好的解决办法。 - pbreitenbach
10个回答

27

在运行rails new MyNewProject命令后,我在一个旧项目上遇到了这个问题。

为了解决旧项目中的问题,我只需进入Gemfile.lock文件,并搜索rake。然后我找到了rake(10.3.2)并将其替换为rake(10.4.2),这样问题就解决了。


20

通常不应手动编辑 gemfile.lock 文件。如果你确实删除了该文件并重新开始,请确保在你的gemfile 中指定了你要使用的宝石版本,以便能够获得预期的宝石版本。对于这种情况:

$ bundle update rake

对我来说有效。


8

此错误是因为您的gem文件使用了不同版本的rake,所以您需要指定您需要哪个版本的rake,以下内容可能会对您有所帮助:

 bundle exec rake routes

3

如果您需要使用旧版本,只需删除新版本:

gem uninstall rake --version=<newer version>

在您的情况下:
gem uninstall rake --version=10.4.2

3

今天我遇到了这个问题。我使用RubyMine构建一个新项目,它安装了rake 10.4.2。但是我的工作需要使用10.3.2进行db:migrate。

RubyMine的解决方案: 为了解决这个问题,我在RubyMine中打开了db:migrate的运行配置,进入Bundler选项卡,并勾选了“在bundle上下文中运行脚本(bundle exec)”。


2
  1. 手动删除你的Gemfile.lock文件
  2. 运行bundle install

这对我来说解决了问题。


2
您可以使用以下命令删除较旧版本的gem: gem uninstall rake --version=[您要删除的版本号] 卸载后,只需正常使用rake routes即可。

0

你可能需要更新你的gemfile.lock文件,并将rake的版本从10.4.0更改为10.4.2,这样你就可以像以前一样继续工作了。


0

该命令

bundle exec rake routes 

虽然这样做可以让它工作,但如果您选择正确的rake版本并在Gemfile.lock中进行更改,效果会更好。


-1

对我来说有两个答案:

  1. 临时解决方案:

bundle exec rake routes

  1. 永久解决方案:

gem update rake 然后 rake routes


我没有在这里进行踩票,只是想澄清一下。起初我想评论一下,“为什么要踩票,当更专注的更新更安全时?”但后来我注意到它建议使用“gem update rake”而不是“bundle update rake”。可能的问题是系统超前于旧项目的bundle。所以需要执行“bundle update [rake]”。而“bundle update rake”只会执行必要的操作,而“bundle update”很可能会触发其他问题并增加更多工作量。当然,定期进行广泛的更新是一个好主意,但应该是经过计算的决定。 - elc
这是我情况下的确切解决方案,针对确切的问题。所以对我来说仍然是最佳答案。如果对你们没有用,很抱歉。 - cibinlik
@elc 首先,感谢您的澄清。奇怪的是,“bundle update rake”并没有解决我的问题,但“gem update rake”却解决了。我已经从这个问题的顶部到底部阅读了答案,并尝试了其他一些门户网站上的问题的答案。最终,“gem update rake”对我来说是正确的答案。我不知道背后的逻辑。也许“downvoter”可以告诉我们。 - cibinlik

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接