当我在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路径存在冲突吗?谢谢你的帮助。
答案 0 :(得分:3)
我总是建议在任何此类命令之前使用“bundle exec”
bundle exec rake db:migrate
答案 1 :(得分:1)
你已经用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),您需要重新启动计算机才能使其生效。