【问题标题】:How to install additional gems with bundler in production environment?如何在生产环境中使用 bundler 安装额外的 gem?
【发布时间】:2016-10-18 13:48:05
【问题描述】:

我有一个登台服务器。我有一些问题要调查。但是我忘记在Gemfile 中添加byebug。我当然可以在本地添加它,运行bundle,提交到存储库,部署。但是没有更简单的方法吗?

当我尝试远程更改Gemfile 并运行bundle 时,我得到:

You are trying to install in deployment mode after changing
your Gemfile. Run `bundle install` elsewhere and add the
updated Gemfile.lock to version control.

If this is a development machine, remove the /home/gccs/website-backend/releases/20161018143057/Gemfile freeze
by running `bundle install --no-deployment`.

You have added to the Gemfile:
* byebug

gems 是用capistrano 安装的,基本上是这样的:

bundle install --path /home/user/app/shared/bundle --without development test --deployment --quiet

【问题讨论】:

    标签: ruby bundler production-environment


    【解决方案1】:

    编辑.bundle/config 将BUNDLE_FROZEN: '1' 更改为'0'(或删除它)就足以让Bundler 允许在部署环境中管理gem。然后你可以编辑Gemfile,运行bundle,重新启动你的应用程序,自定义的gem就可以使用了。

    如果您打算在应用程序运行时之外使用它们(例如,如果您在 rails console 中需要 pry)则不需要重新启动服务器。

    【讨论】:

    • 我在问题中添加了更多信息。我可以说,bundler 产生与Gemfile.local 相同的错误消息。
    • 您需要编辑.bundle/config 并删除此行:BUNDLE_FROZEN: '1'。这开始变得比提交、推送和部署更复杂;)
    • You need to edit .bundle/config and remove this line: BUNDLE_FROZEN: '1' 或者只是将其更改为“0”。无论如何,很好,它有效,谢谢。 This is starting becoming more complex than commit, push and deploy 嗯,一点也不,你只需要“解冻”更改Gemfile,更改Gemfile,然后运行bundle。不需要Gemfile.local。请考虑更新您的答案。
    • 不确定这是否是正确的做法,但我决定创建自己的答案。我不喜欢你的是它有不相关的细节(Gemfile.local)。好吧,如果只是那样的话,我可能不会在意。但它从他们开始,几乎给他们带来了压力。如果您删除 Gemfile.local 部分,或者至少将其移到末尾,我会接受您的回答。
    • 啊,是的,实际上删除BUNDLE_FROZEN 就足够了。我会更新我的答案。
    【解决方案2】:

    您无法安装其他 gem 的原因是捆绑包已冻结。你可以这样检查:

    $ grep FROZEN .bundle/config
    BUNDLE_FROZEN: '1'
    

    如果您删除该行(如mdesantis 所建议)或将“1”更改为“0”,您将能够安装您喜欢的任何 gem,就好像它是开发人员机器一样。但一般来说,如果不再需要,最好恢复该值。不确定bundler 是否会在下次部署时自动执行此操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-20
      相关资源
      最近更新 更多