Ruby/gems升级后,非交互式SSH执行Bundler部署偶现“List of sources changed”错误求助
Ruby/gems升级后,非交互式SSH执行Bundler部署偶现“List of sources changed”错误求助
最近把Ruby升级到2.7.8,同步更新了Nokogiri到1.15.4,还通过bundle lock --add-platform x86_64-linux给Gemfile加了Linux平台支持,结果部署服务器时遇到了特别诡异的问题:交互式SSH跑部署脚本完全正常,非交互式SSH执行就直接报错卡壳。
问题重现流程
- 本地开发环境正常跑
bundle install,把Gemfile和Gemfile.lock提交到GitHub - 交互式SSH登录服务器后运行部署脚本:拉取最新代码、执行
bundle install、重启服务器,全程顺畅,新gem正常加载生效 - 非交互式SSH直接执行部署脚本时,立刻抛出部署模式错误,流程中断
具体错误内容
Bundler::ProductionError: You are trying to install in deployment mode after changing
your Gemfile. Runbundle installelsewhere and add the
updated Gemfile.lock to version control.
If this is a development machine, remove the /srv/code/Gemfile freeze
by runningbundle config unset deployment.
The list of sources changed
我猜应该是非交互式shell下RVM没正确初始化,但试了几种方法都没搞定。
已尝试的排查操作
- 把默认RVM版本重置为当前使用的Ruby 2.7.8
- 在部署脚本开头手动加了
. /etc/profile.d/rvm.sh,强制初始化RVM
关键配置细节
.bundle/config 文件内容
BUNDLE_DEPLOYMENT: "true" BUNDLE_PATH: "vendor/bundle" BUNDLE_WITHOUT: "onsite:development:test"
部署脚本核心代码
git fetch --all git reset --hard origin/production . /etc/profile.d/rvm.sh /usr/share/rvm/gems/ruby-2.7.8/bin/bundler install
Gemfile.lock 里的平台声明
PLATFORMS ruby x86_64-darwin-20 x86_64-linux
最费解的点
为什么这两种执行方式结果天差地别?
- 正常工作的交互式执行:
ssh user@server.com /usr/share/rvm/rubies/ruby-2.7.8/bin/ruby /path_to_script/deploy.rb - 报错的非交互式执行:
ssh user@server.com '/usr/share/rvm/rubies/ruby-2.7.8/bin/ruby /path_to_script/deploy.rb'
补充环境信息:
- Bundler版本:2.4.18
- Rails版本:4.2.11.34(Rails LTS)
- Ruby版本:2.7.8
备注:内容来源于stack exchange,提问作者Mike
相关产品推荐
相关产品推荐

