0

简而言之,错误消息如下所示:

$ bundle install
rake aborted!
You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.9.2. Using bundle exec may solve this.

这是此错误的解释:

  • 部署服务器已rake 0.9.2.2安装
  • 应用程序Gemfile没有所需的版本号rake
  • 开发者的开发环境rake安装了0.9.2,这个版本号在Gemfile.lock文件中
  • 部署服务器安装了许多 Rails 应用程序
  • 这些应用程序由不同的程序员编写
  • 这些程序员在他们的开发环境中安装了不同的 rake 版本
  • 其中一些有rake 0.9.2,另一些有rake 0.9.2.2
  • 通过阅读Yehuda Katz 的 Clarifying the Roles of the .gemspec 和 GemfileGemfile.lock文件在我们的颠覆中

可能的解决方案:

  • 可以通过运行bundle exec rake installthen来避免错误消息bundle update
  • 如果我们要求所有开发人员指定相同版本的 rake in,则可以避免错误消息Gemfile
  • 要求所有开发人员使用相同版本的 rake

我的问题是:这是正确的解决方案吗?还是有任何正确的解决方案?

我仍然不确定该Gemfile.lock文件是否应该处于颠覆状态。

4

2 回答 2

4

您绝对应该检查您的 Gemfile.lock。它包含您知道将与您的应用程序一起使用的 gem 版本。因此,当您在不同的环境中捆绑安装时,您知道它应该可以工作。

假设几个月后有人在没有 Gemfile.lock 的情况下进行捆绑安装。他们将在您的 Gemfile 中获得最新版本的 gem(至少是具有指定版本的 gem),并且无法保证您的应用程序甚至可以使用这些 gem。使用 Gemfile.lock,应该可以确保您的应用程序应该运行,因为任何使用过它或对其进行测试的人都应该在那些冻结的 gem 版本中让它处于通过状态。

为了解决您的问题,我会这样做:

bundle update rake

然后提交 Gemfile 和 Gemfile.lock。这样,您就可以告诉运行您的应用程序的任何人您应该使用 0.9.2.2 的 rake。这是您知道将与您的应用程序一起使用的 rake 版本,并且您的测试是针对此版本运行的。

要实际运行正确的版本,您有几个选项:

  • 捆绑执行:

    $ bundle exec rake -T
    

为 .bash_profile、.zshrc 或 .profile 添加别名也可能有帮助:

# in .bash_profile
alias b="bundle exec"
$ b rake -T
  • 捆绑箱存根

    # in your .bash_profile
    export PATH="./.bin:$PATH"
    $ bundle install --binstubs
    

这会将您的 Gemfile 的二进制文件安装到 ./bin 目录,并且路径更改将强制您的 shell 在查看 rvm 或您的 gem install 二进制文件之前先签入 ./bin。如果您这样做,请记住将“bin”添加到您的 .gitignore 文件中。

  • rubygems 捆绑器宝石。此 gem 生成包装器,尝试确定何时为您使用 bundle exec。
于 2012-02-10T08:52:26.880 回答
1

The productivity drain your team will experience with trying to keep everyone on the same version of rake (2nd and 3rd solutions) and managing all the downstream conflicts could be very high. It will also raise the level of developer frustration when they need to use gem/script/module XYZ but there is a problem with XYZ and the mandated version of rake.

As long as take steps to ensure the bundle commands execute efficiently in your environment, Solution 1 will make a much smaller negative impact on the productivity of your teams. IMHO.

于 2012-02-10T09:01:33.840 回答