You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Ruby版本后Capistrano部署找不到指定Bundler版本

解决Capistrano部署时找不到指定Bundler版本的问题

检查Capistrano的Bundler版本配置

Capistrano默认可能未强制指定Bundler版本,需要在部署配置里明确指定:

  • 在config/deploy.rb中添加或修改以下配置:
    set :bundle_version, '1.17.2'
    set :bundle_flags, '--deployment --quiet'
    
    该配置会让Capistrano在部署流程中强制使用你指定的Bundler版本。

确认服务器上Bundler的路径与Ruby环境匹配

Ruby 2.7.6安装的Bundler可能不在Capistrano默认的环境变量路径中,需要确保路径正确:

  • 登录部署服务器,执行which bundler,检查输出路径是否对应Ruby 2.7.6的安装目录(比如~/.rbenv/shims/bundler或~/.rvm/gems/ruby-2.7.6/bin/bundler);
  • 如果路径不匹配,在config/deploy.rb中指定Bundler的绝对路径:
    set :bundle_cmd, '/path/to/ruby-2.7.6/bin/bundler'
    

重新生成并同步Gemfile.lock

本地生成的Gemfile.lock可能存在环境不一致的问题,需要用指定Bundler版本重新生成:

  • 本地执行bundle _1.17.2_ install,确保Gemfile.lock是由目标版本Bundler生成;
  • 将更新后的Gemfile.lock提交到版本库,再重新执行部署。

清理服务器上的旧Bundler缓存

服务器可能残留旧缓存导致版本冲突,可手动清理或添加部署任务:

  • 登录服务器,进入项目current目录,执行bundle _1.17.2_ clean --force;
  • 或者在config/deploy.rb中添加前置清理任务:
    before 'bundle:install', 'bundle:clean'
    
    namespace :bundle do
      desc 'Clean old bundle cache'
      task :clean do
        on roles(:app) do
          within release_path do
            execute :bundle, '_1.17.2_', 'clean', '--force'
          end
        end
      end
    end
    

确保Capistrano使用目标Ruby版本

确认Capistrano部署时切换到Ruby 2.7.6:

  • 若使用rbenv,在config/deploy.rb添加:
    set :rbenv_ruby, '2.7.6'
    
  • 若使用rvm,添加:
    set :rvm_ruby_version, '2.7.6'
    

内容的提问来源于stack exchange,提问作者GTO

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 12:35:18