Ruby-on-rails Bundler:您在更改 Gemfile 后尝试在部署模式下安装

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11513623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 03:42:10  来源:igfitidea点击:

Bundler: You are trying to install in deployment mode after changing your Gemfile

ruby-on-railscapistranobundler

提问by JellicleCat

I'm pretty new to bundler and capistrano, and I'm trying to use them together. When I try to deploy, I get the message:

我对 bundler 和 capistrano 还很陌生,我正在尝试将它们一起使用。当我尝试部署时,我收到以下消息:

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.

您在更改 Gemfile 后尝试在部署模式下安装。在别处运行 `bundle install' 并将更新的 Gemfile.lock 添加到版本控制。

I don't know how to satisfy the system that's complaining, and I don't understand why the complaint is coming up because I read in the doc:

我不知道如何满足抱怨的系统,我不明白为什么会出现抱怨,因为我在文档中读到:

If a Gemfile.lock does exist, and you have updated your Gemfile(5), bundler will use the dependencies in the Gemfile.lock for all gems that you did not update, but will re-resolve the dependencies of gems that you did update. You can find more information about this update process below under CONSERVATIVE UPDATING.

如果 Gemfile.lock 确实存在,并且您已经更新了 Gemfile(5),bundler 将使用 Gemfile.lock 中所有您未更新的 gem 中的依赖项,但会重新解析您已更新的 gem 的依赖项. 您可以在下面的 CONSERVATIVE UPDATING 下找到有关此更新过程的更多信息。

I interpret that to mean that the Bundler can handle the fact that my Gemfile is not whatever it expected. Any help?

我认为这意味着 Bundler 可以处理我的 Gemfile 与预期不同的事实。有什么帮助吗?

Specs: Ruby 1.9.3, Rails 3.2.3, Capistrano 2.12.0, Bundler 1.1.4, Windows 7, deploying to a Posix machine.

规格:Ruby 1.9.3、Rails 3.2.3、Capistrano 2.12.0、Bundler 1.1.4、Windows 7,部署到 Posix 机器。

Edit:My Gemfile includes logic blocks like the following:

编辑:我的 Gemfile 包括如下逻辑块:

unless RbConfig::CONFIG['host_os'] === 'mingw32'
  # gem 'a' ...
end

采纳答案by Edd Morgan

The error message you're getting regarding Gemfile.lockmay be because your Gemfileand Gemfile.lockdon't agree with each other. It sounds like you've changed something in your Gemfile since you last ran bundle install(or update). When you bundle install, it updates your Gemfile.lock with any changes you've made to Gemfile.

您收到的错误消息Gemfile.lock可能是因为您GemfileGemfile.lock彼此不同意。听起来您自上次运行bundle install(或update)以来已经更改了 Gemfile 中的某些内容。当您使用bundle install它时,它会使用您对 Gemfile 所做的任何更改来更新您的 Gemfile.lock。

Make sure you run bundle installlocally, and check-in to source control your newly updated Gemfile.lockafter that. Then try deploying.

确保您在bundle install本地运行,并在此之后签入以进行源代码控制Gemfile.lock。然后尝试部署。

Edit: As recognised in the comments, a conditional in the Gemfile resulted in a valid Gemfile.lock on one platform, invalid on another. Providing a :platformflag for these platform-dependent gems in the Gemfile should solve the asymmetry.

编辑:正如评论中所承认的,Gemfile 中的条件导致一个平台上的 Gemfile.lock 有效,而另一个平台上无效。在 Gemfile 中为这些平台相关的 gem提供一个:platform标志应该可以解决不对称问题。

回答by Gaurav24

vi .bundle/config

vi .bundle/config

change the BUNDLE_FROZEN option from '1' to '0'

将 BUNDLE_FROZEN 选项从“1”更改为“0”

do "bundle install"

做“捆绑安装”



OR

或者

run "bundle config"

运行“捆绑配置”

see if the "frozen" value is true set it to false

查看“冻结”值是否为真将其设置为假

bundle config frozen false

捆绑配置冻结假

回答by Joshua Pinter

Watch out for global Bundler config.

注意全局 Bundler 配置。

I had a global config on my dev environment in ~/.bundle/configthat I did not have in my CI / Production environment that caused the Gemfile.lockthat was generated in my dev environment to be different than the one in my CI / Production environment.

我的开发环境中有一个全局配置~/.bundle/config,因为我的 CI / 生产环境中没有,这导致Gemfile.lock开发环境中生成的配置与 CI / 生产环境中生成的配置不同。

In my case I was setting github.httpsto true in my dev environment but had no such config in my CI / Production environment. This caused the two Gemfile.lockfiles to be different.

就我而言,我github.https在开发环境中设置为 true,但在 CI/生产环境中没有这样的配置。这导致两个Gemfile.lock文件不同。

回答by l3x

When you see the following...

当你看到以下...

$ bundle install
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 Gemfile freeze
by running `bundle install --no-deployment`.

You have added to the Gemfile:
* source: rubygems repository https://rubygems.org/
* rails (~> 3.2)
. . .

... Then, the problem is most likely that you have outdated .gem files in your vendor/cache directory.

...然后,问题很可能是您的供应商/缓存目录中的 .gem 文件已过时。

Perhaps, you previously ran $bundle install --deploymentwhich put some "outdated" .gem files in the cache?

也许,您之前运行过$bundle install --deployment将一些“过时”的 .gem 文件放入缓存中?

In any case, you can get past this error by running: bundle install --no-deployment

在任何情况下,您都可以通过运行来克服这个错误: bundle install --no-deployment

That's one of the many great things about Rails... the error messages often tell you exactly what to do to fix the problem.

这是 Rails 的众多优点之一……错误消息通常会准确地告诉您如何解决问题。

回答by Giuseppe

My specific problem was related to what reported by @JoshPinter, i.e. dev-vs-deploy host discrepancies in the protocol used by bundler to retrieve gems from github.

我的具体问题与@JoshPinter 报告的内容有关,即 bundler 用于从 github 检索 gems 的协议中的 dev-vs-deploy 主机差异。

To make a long story short, all I had to was modify the following Gemfileentry...

长话短说,我所要做的就是修改以下Gemfile条目......

gem 'activeadmin', github: 'activeadmin'

...to this secure syntax (see reference):

...这个安全的语法(见参考):

gem 'activeadmin', git: 'https://github.com/activeadmin/activeadmin.git'

And my deployments are back to normal.

我的部署恢复正常。

回答by dacoinminster

The solution for me was slightly different than the others listed here. I was trying to upgrade from sidekiq to sidekiq-pro (which requires bundler 1.7.12+), but I kept getting the "You are trying to install in deployment mode after changing your Gemfile" message from travis-ci

我的解决方案与此处列出的其他解决方案略有不同。我试图从 sidekiq 升级到 sidekiq-pro(这需要 bundler 1.7.12+),但我不断收到来自 travis-ci 的“您正在尝试在更改 Gemfile 后以部署模式安装”消息

Inspecting the console output of travis-ci revealed that an older version of bundler was being used.

检查 travis-ci 的控制台输出显示正在使用旧版本的 bundler。

In my case, I had to edit the travis.yml file to add:

就我而言,我必须编辑 travis.yml 文件以添加:

before_install: - gem update bundler

before_install: - gem update bundler

This forced travis-ci to use the latest version of bundler, and made the error message go away.

这迫使 travis-ci 使用最新版本的 bundler,并使错误消息消失。

回答by Aneil Mallavarapu

rm -fr .bundle

Fixed the problem for me.

为我解决了问题。

回答by William Entriken

I don't care. This is what I did. It fixed it.

我不在乎。这就是我所做的。它修复了它。

rm -rf .bundle 
rm -rf Gemfile.lock
bundle install

回答by Chewbarkla

This might be a dangerous idea, but if absolutely must test something in a production deploy environment, you can edit the .bundle/config file

这可能是一个危险的想法,但如果绝对必须在生产部署环境中测试某些内容,您可以编辑 .bundle/config 文件

# This value is normally '1' 
# Set it to '0'
BUNDLE_FROZEN: '0'

Now invoke bundle, in my case I needed to update a specific gem, so this my command

现在调用 bundle,在我的情况下,我需要更新一个特定的 gem,所以这是我的命令

RAILS_ENV=production bundle update <whatever gem>

You should probably change it back after the update, so things work like you expect, afterwards. Again, this is probably unsupported, and YMMV

您可能应该在更新后将其改回,这样之后的事情就会如您所愿。同样,这可能不受支持,YMMV

回答by bobbdelsol

Another cause of the error:

另一个错误原因:

This is a bit foolish, but i'm sure someone else will make the same mistake.

这有点愚蠢,但我相信其他人会犯同样的错误。

For Rails 4 Heroku added the gem rails_12factor. If you were using it before they added it, then you'll have these two gems:

对于 Rails 4 Heroku 添加了 gem rails_12factor。如果您在添加它之前使用它,那么您将拥有以下两个宝石:

gem 'rails_log_stdout',  github: 'heroku/rails_log_stdout'
gem 'rails3_serve_static_assets', github: 'heroku/rails3_serve_static_assets'

You have to remove them when you add the new one. (they're included). I think you can get away with it until you touch them lines in your gem file, then Heroku notices the duplication and cries out with the above error.

当您添加新的时,您必须删除它们。(它们包括在内)。我认为你可以摆脱它,直到你在你的 gem 文件中触摸它们的行,然后 Heroku 注意到重复并发出上述错误。

good luck with Rails 4.

祝 Rails 4 好运。