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

Ruby Bundler无法连接rubygems.org的问题求助

RubyGems 连接 rubygems.org 超时问题

问题详情

创建新 Rails 应用时,执行 bundle install 持续抛出以下错误:

Retrying fetcher due to error (2/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/ due to underlying error <Gem::Net::OpenTimeout: Failed to open TCP connection to rubygems.org:443 (execution expired) (https://rubygems.org/specs.4.8.gz)>

浏览器可正常访问 rubygems.org,但运行 gem install bundler 时也出现完全一致的错误,推测问题出在 RubyGems 的网络连接层面。

gem env 输出信息

RubyGems Environment:
  - RUBYGEMS VERSION: 3.5.11
  - RUBY VERSION: 3.3.4 (2024-07-09 patchlevel 94) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/aino/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0
  - USER INSTALLATION DIRECTORY: /home/aino/.local/share/gem/ruby/3.3.0
  - RUBY EXECUTABLE: /home/aino/.rbenv/versions/3.3.4/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /home/aino/.rbenv/versions/3.3.4/bin
  - SPEC CACHE DIRECTORY: /home/aino/.cache/gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /home/aino/.rbenv/versions/3.3.4/etc
  - RUBYGEMS PLATFORMS:
     - ruby
     - x86_64-linux
  - GEM PATHS:
     - /home/aino/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0
     - /home/aino/.local/share/gem/ruby/3.3.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => true
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /home/aino/.rbenv/versions/3.3.4/bin
     - /usr/lib64/rbenv/libexec
     - /home/aino/.rbenv/plugins/ruby-build/bin
     - /home/aino/.opam/default/bin
     - /home/aino/.local/bin
     - /run/user/1000/fnm_multishells/4864_1724445534233/bin
     - /home/aino/.local/share/fnm
     - /home/aino/.rbenv/shims
     - /home/aino/.cargo/bin
     - /usr/local/bin
     - /usr/local/sbin
     - /usr/bin
     - /usr/sbin

可行解决方案

  • 同步命令行代理设置:浏览器可访问但命令行工具失败,大概率是命令行未使用正确代理。检查并设置环境变量:
    export http_proxy=http://你的代理地址:端口
    export https_proxy=http://你的代理地址:端口
    
    设置完成后重新尝试 gem install bundler 或 bundle install。
  • 切换国内镜像源:若代理无效,替换为国内稳定的 RubyGems 源:
    gem sources --remove https://rubygems.org/
    gem sources --add https://gems.ruby-china.com/
    
    执行 gem sources -l 确认源已切换,再执行安装命令。
  • 排查防火墙/网络限制:系统防火墙或本地安全软件可能拦截 Ruby 程序的网络请求,可临时关闭防火墙测试,或添加规则允许 Ruby 进程访问网络。
  • 延长超时时间:通过参数增加 Gem 连接超时时长:
    gem install bundler --timeout 120
    
    或在项目目录创建 .bundle/config 文件,添加配置:
    BUNDLE_TIMEOUT: "120"
    
  • 清理 RubyGems 缓存:删除旧的 spec 缓存后更新 RubyGems:
    rm -rf /home/aino/.cache/gem/specs
    gem update --system
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 08:52:28