【问题标题】:How to control dependency gem versions?如何控制依赖 gem 版本?
【发布时间】:2016-01-15 13:32:02
【问题描述】:

我创建了一个新的 AWS ubuntu 服务器并尝试在其上安装 Unicorn(使用 salt-stack 和手动),但失败并出现以下错误。

[INFO    ] Running state [unicorn] at time 12:18:59.787564
[INFO    ] Executing state gem.installed for unicorn
[INFO    ] Executing command 'gem list unicorn' in directory '/home/ubuntu'
[INFO    ] Executing command '/usr/local/rbenv/bin/rbenv rehash ' in directory '/home/ubuntu'
[INFO    ] Executing command 'gem install unicorn --version 4.8.2 --no-rdoc --no-ri' in directory '/home/ubuntu'
[ERROR   ] Command 'gem install unicorn --version 4.8.2 --no-rdoc --no-ri' failed with return code: 1
[ERROR   ] stderr: ERROR:  Error installing unicorn:
    rack requires Ruby version >= 2.2.2.
[ERROR   ] retcode: 1
[ERROR   ] Could not install gem.

几个月前我创建了一个类似的服务器,安装工作正常。它失败了,因为在安装 unicorn gem(4.8.2) 时它安装了 rack gem(1.6.4) 作为独角兽依赖项。 rack 1.6.4 依赖于 ruby​​ 2.2.2 所以安装失败。

我手动安装了rack version 1.6.2,然后尝试安装unicorn 4.8.2,它成功了。

现在的问题是如何避免这种不一致,我能想到的一种解决方案是手动安装所有依赖项 gem,但这需要付出很多努力。有什么办法可以锁定 gem 版本和 gem 依赖版本?

【问题讨论】:

    标签: ruby-on-rails ruby rubygems


    【解决方案1】:

    你使用捆绑器吗?不看就看http://bundler.io/

    您可以使用它在 Gemfile 中定义 gem 的版本。当您运行bundle install 时,将生成一个名为 Gemfile.lock 的文件,其中所有 gem 版本及其依赖项均已锁定。

    【讨论】:

    • 我使用 bundler,但问题是我安装了一些 gems 作为基础设施的一部分,比如 unicorn、capistrano、backup、mailer 和一些 gems 作为应用程序的一部分。应用程序 gems 是使用 bundler 安装的,而不是基础设施 gems
    • 我会将应用程序所需的所有 gem 添加到它的 Gemfile 中,因为这样应用程序会承载它的所有依赖项。在应用程序恕我直言之外安装依赖项很脆弱。
    猜你喜欢
    • 1970-01-01
    • 2017-09-20
    • 1970-01-01
    • 2011-06-25
    • 1970-01-01
    • 2020-02-27
    • 2017-01-30
    • 2016-01-27
    • 2023-03-31
    相关资源
    最近更新 更多