【问题标题】:After installing rbenv and changing Ruby version, Rake no longer runs安装 rbenv 并更改 Ruby 版本后,Rake 不再运行
【发布时间】:2012-03-14 00:21:46
【问题描述】:

安装 Rbenv 和 Ruby 1.9.2 和 1.8.7 后,将当前项目设置为使用 1.9.2(之前使用 1.8.7),Rake 将不再运行。运行 rake routes 会给出消息:

Could not find rake-0.8.7 in any of the sources
Run `bundle install` to install missing gems.

这是在运行 bundle install 之后。

尝试bundle exec rake routes(这是安装 Rbenv 之前使用的方法),会产生以下错误:

NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /Library/Ruby/Gems/1.8/gems/bundler-1.0.9/lib/bundler/shared_helpers.rb:3.
Invalid gemspec in [/Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.8/specifications/jquery-rails-1.0.19.gemspec]: invalid date format in specification: "2011-11-26 00:00:00.000000000Z"
Invalid gemspec in [/Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.8/specifications/tilt-1.3.3.gemspec]: invalid date format in specification: "2011-08-25 00:00:00.000000000Z"
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /Library/Ruby/Gems/1.8/gems/bundler-1.0.9/lib/bundler/source.rb:161.
NOTE: Gem::SourceIndex#each is deprecated with no replacement. It will be removed on or after 2011-11-01.
Gem::SourceIndex#each called from /Library/Ruby/Gems/1.8/gems/bundler-1.0.9/lib/bundler/source.rb:161.
Could not find rake-0.8.7 in any of the sources

请注意,应用程序本身在开发过程中运行没有问题(rails crails s 等)。

另请注意,gem list 将 rake (0.8.7) 列为本地 gem。

如果我将 gemfile 更改为请求 rake 版本 0.9.2,然后更新捆绑包(捆绑更新 rake),我会得到相同的错误,除了它们现在引用 rake 的版本 0.9.2 而不是 0.8.7。

【问题讨论】:

  • 你在安装 rubies 后运行rbenv rehash 了吗?另外,您是否按照说明将 shims 目录添加到您的路径?
  • 我做了echo 'eval "$(rbenv init -)"' >> ~/.bash_profile,然后是exec $SHELL,如 Sam Stephenson 关于安装 rbenv 的文档的第 2.1 节的第 3 和第 4 步中所述,如果这就是你的意思。我不知道启用垫片的任何其他步骤。是否有独立的方法来测试垫片是否启用?

标签: ruby-on-rails rake bundler rbenv


【解决方案1】:

安装新的 ruby​​ 版本后,您需要运行 rbenv rehash。接下来,运行 gem install rake,然后在 rake 安装二进制文件时再次运行 rbenv rehash

【讨论】:

  • 做到了。现在得到Could not find rake-0.9.2 in any of the sourcesRun 'bundle install' to install missing gems.bundle install 并得到Unfortunately, a fatal error has occurred. Please report this error to the Bundler issue tracker at https://github.com/carlhuda/bundler/issues so that we can fix it。按要求报告错误。
  • 在谷歌搜索后,尝试bundle update,在报告它正在安装 linecache (0.46) 并从 ruby​​ gems/installer.rb (line第552章)。
  • 回顾您的第一个错误,其中提到了系统 ruby​​ (/Library/Ruby/Gems/1.8/...)。我怀疑您可能在第一次重新哈希之前尝试安装 rake,这使事情变得混乱。如果我是您,我会删除 ~/.rbenv/versions/1.9.2 目录并重新开始。另外,您是否在安装 rbenv 和之前安装新版本的 ruby​​ 之后将 eval "$(rbenv init -)" 添加到 ~/.profile
  • 所以如果我正确理解了你的建议,我应该从 rbenv 中删除 ruby​​ 1.9.2 目录,重新安装 ruby​​ 1.9.2,重新散列,安装 rake,然后再次重新散列。正确的?我确实将rbenv init - 命令添加到了我的bash 启动文件中。不能保证我是在安装新版本的 ruby​​ 之前还是之后这样做的。但是我在添加命令后确实重新启动了 shell(即 exec $SHELL)。
【解决方案2】:

根本原因是 gem 文件,它仍然引用 ruby-debug。将其更改为ruby-debug19,执行bundle installbundle update,现在rake 工作正常。无法解释为什么应用程序在引用 ruby​​-debug 时运行良好。

【讨论】:

    【解决方案3】:

    我遇到了同样的问题。我的问题的原因是除了在 r​​benv 的 shims 目录中之外,还在/usr/bin/local/ 中找到了 Rake。要检查这是否是问题,首先卸载 rake gem uninstall rake,然后运行 ​​which rake。如果您返回的路径与 /Users/username/.rbenv/shims/rake 不同,则只需使用 sudo rm /path/to/file 删除该二进制文件。

    请注意,至少在我的情况下,which gem 使用的是由 rbenv 管理的 shimed 可执行文件,而 rake 不是。所以一切正常,直到我尝试从终端调用rake command

    【讨论】:

      【解决方案4】:

      您应该尝试使用chruby 而不是 rbenv。与 rbenv 不同,chruby 不依赖 shims;所以不再需要一直运行rehash。相反,chruby 只修改PATHGEM_HOMEGEM_PATH

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-06-12
        • 1970-01-01
        • 2018-01-03
        • 1970-01-01
        • 1970-01-01
        • 2012-12-02
        相关资源
        最近更新 更多