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

Linux环境下执行bundle install遇CA证书验证失败求助

解决Linux下bundle install的SSL证书验证失败问题

方法1:修复证书权限与命名

Gem的SSL证书目录要求证书文件权限正确,且文件名需为证书哈希值加.0,执行以下操作:

  • 修正证书权限:
    sudo chmod 644 /usr/lib/ruby/vendor_ruby/rubygems/ssl_certs/rubygems.org/GlobalSignRootCA_R3.pem
    sudo chmod 644 /usr/lib/ruby/3.0.0/rubygems/ssl_certs/GlobalSignRootCA_R3.pem
    
  • 生成证书哈希并创建软链接:
    # 处理第一个证书目录
    cd /usr/lib/ruby/vendor_ruby/rubygems/ssl_certs/rubygems.org
    # 获取证书哈希值(假设输出为`abcdef12`)
    openssl x509 -hash -noout -in GlobalSignRootCA_R3.pem
    # 创建软链接
    sudo ln -s GlobalSignRootCA_R3.pem abcdef12.0
    
    # 处理第二个证书目录
    cd /usr/lib/ruby/3.0.0/rubygems/ssl_certs
    openssl x509 -hash -noout -in GlobalSignRootCA_R3.pem
    sudo ln -s GlobalSignRootCA_R3.pem abcdef12.0
    

方法2:利用系统级CA证书

将证书导入系统信任池,让Ruby优先使用系统证书:

  • 复制证书到系统CA目录并更新缓存:
    sudo cp ~/GlobalSignRootCA_R3.pem /etc/ssl/certs/
    sudo update-ca-certificates
    
  • 设置环境变量指定证书路径,再执行bundle:
    # 方式1:指向单个证书文件
    export SSL_CERT_FILE=/etc/ssl/certs/GlobalSignRootCA_R3.pem
    bundle install
    
    # 方式2:指向系统完整证书 bundle(更推荐)
    export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
    bundle install
    
    若要永久生效,可将export SSL_CERT_FILE=...添加到~/.bashrc或~/.zshrc中。

方法3:重新安装Ruby并绑定正确的OpenSSL

部分Ruby版本可能因编译时OpenSSL配置问题导致证书验证失败,用版本管理工具重新安装:

  • 若使用rbenv:
    RUBY_CONFIGURE_OPTS="--with-openssl-dir=/usr" rbenv install 3.0.0
    rbenv global 3.0.0
    bundle install
    
  • 若使用rvm:
    rvm install 3.0.0 --with-openssl-dir=/usr
    rvm use 3.0.0 --default
    bundle install
    

方法4:直接在bundle命令或Gemfile中指定证书

  • 临时指定证书执行bundle:
    bundle install --ssl-ca-cert ~/GlobalSignRootCA_R3.pem
    
  • 或在Gemfile中添加证书配置:
    source 'https://rubygems.org' do
      ssl_ca_cert '/home/your-username/GlobalSignRootCA_R3.pem'
    end
    
    替换/home/your-username/为你的实际用户路径。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 17:17:24