捆绑更新rake没有修复我的’你已经激活了rake …’错误

当我在Ubuntu终端中运行rake db:migrate ,我不断收到错误:

 rake aborted! You have already activated rake 10.0.4, but your Gemfile requires rake 0.9.6. Using bundle exec may solve this. 

我在stackoverflow上看到一种解决这个问题的方法是运行:

 bundle update rake 

所以我这样做,我得到:

 Fetching gem metadata from https://rubygems.org/....... Fetching gem metadata from https://rubygems.org/.. Enter your password to install the bundled RubyGems to your system: Using rake (0.9.6) Using SystemTimer (1.2.3) etc... etc... Your bundle is updated! Use `bundle show [gemname]` to see where a bundled gem is installed. 

这不应该将rake更新到10.0.4吗? 因为当我运行rake db:migrate我仍然得到错误:

 rake aborted! You have already activated rake 10.0.4, but your Gemfile requires rake 0.9.6. Using bundle exec may solve this. 

我有什么想法可以解决这个问题吗? 当我运行gem env我得到:

 RubyGems Environment: - RUBYGEMS VERSION: 1.8.15 - RUBY VERSION: 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux] - INSTALLATION DIRECTORY: /var/lib/gems/1.8 - RUBY EXECUTABLE: /usr/bin/ruby1.8 - EXECUTABLE DIRECTORY: /usr/local/bin - RUBYGEMS PLATFORMS: - ruby - x86_64-linux - GEM PATHS: - /var/lib/gems/1.8 - /home/mycompaq/.gem/ruby/1.8 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - REMOTE SOURCES: - http://rubygems.org/ 

可能与GEM路径存在冲突吗? 谢谢你的帮助。

我总是建议在任何这样的命令之前使用“bundle exec”

 bundle exec rake db:migrate 

你用rvm标记了你的问题 – 所以我假设你使用RVM,但是你的gem env看起来不像你使用rvm安装的ruby,要做到这一点你需要运行:

 rvm use ruby --version bundle install 

默认情况下rvm附带rubygems-bundler gem,它会为你自动执行bundle exec ,所以它应该足够:

 rake db:migrate 

在使用rvm安装ruby之后,要使下一个会话的ruby默认运行:

 rvm use ruby --default 

在极少数情况下(如系统安装或osx),您需要重新启动计算机才能使其生效。