Ruby 无法连接到 ruby​​gems.org

标签 ruby openssl rubygems bundler

我已经在 J​​ekyll 站点上工作了一个月,没有出现任何问题,但是从本周开始,每次我尝试运行 bundle install 时,我都会收到错误 Bundler::HTTPError无法从 https://rubygems.org 获取规范。我在 macOS 10.13、ruby 2.5.1 上。

这是我的 ruby -ropen-uri -e 'eval open("https://git.io/vQhWq").read'

的输出
Here's your Ruby and OpenSSL environment:

Ruby:           2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
RubyGems:       2.7.7
Bundler:        1.16.2
Compiled with:  OpenSSL 1.0.2o  27 Mar 2018
Loaded version: OpenSSL 1.0.2o  27 Mar 2018
SSL_CERT_FILE:  /usr/local/etc/openssl/cert.pem
SSL_CERT_DIR:   /usr/local/etc/openssl/certs

With that out of the way, let's see if you can connect to rubygems.org...

Bundler connection to rubygems.org:       failed  ❌  (execution expired)
RubyGems connection to rubygems.org:      failed  ❌  (timed out (https://rubygems.org))
Ruby net/http connection to rubygems.org: failed  ❌

Unfortunately, this Ruby can't connect to rubygems.org. 😡
Even worse, we're not sure why. 😕

Here's the full error information:
Net::OpenTimeout: execution expired
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:937:in `initialize'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:937:in `open'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:937:in `block in connect'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/timeout.rb:103:in `timeout'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:935:in `connect'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:920:in `do_start'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:915:in `start'
  (eval):90:in `<main>'
  -e:1:in `eval'
  -e:1:in `<main>'

You might have more luck using Mislav's SSL doctor.rb script. You can get it here:
https://github.com/mislav/ssl-tools/blob/8b3dec4/doctor.rb
Read more about the script and how to use it in this blog post:
https://mislav.net/2013/07/ruby-openssl/

运行上述脚本,我得到:

/usr/local/Cellar/ruby/2.5.1/bin/ruby (2.5.1-p57)
OpenSSL 1.0.2o  27 Mar 2018: /usr/local/etc/openssl
SSL_CERT_DIR=""
SSL_CERT_FILE=""

HEAD https://status.github.com:443
#<Net::HTTPGatewayTimeOut 504 GATEWAY_TIMEOUT readbody=true>

最后,openssl s_client -connect ruby​​gems.org:443 -tls1 显示:

CONNECTED(00000005)
140735672206280:error:1409442E:SSL routines:SSL3_READ_BYTES:tlsv1 alert protocol version:/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-22.50.2/libressl/ssl/s3_pkt.c:1133:SSL alert number 70
140735672206280:error:1409E0E5:SSL routines:SSL3_WRITE_BYTES:ssl handshake failure:/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-22.50.2/libressl/ssl/s3_pkt.c:522:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 0 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1
    Cipher    : 0000
    Session-ID: 
    Session-ID-ctx: 
    Master-Key: 
    Start Time: 1530836427
    Timeout   : 7200 (sec)
    Verify return code: 0 (ok)
---

我知道问题与我的 SSL 证书有关,但我已经更新了 openssl 和 ruby -ropenssl -e "puts OpenSSL::SSL::SSLContext::METHODS.grep(/.+\d $/).sort" 表明我有 TLSv1_2,所以我不知道为什么它不起作用。

我已经为此绞尽脑汁好几天了 - 任何帮助都将不胜感激!谢谢!

更新:还不到几个星期,这个问题就一直消失又回来。前几天我重新启动了我的 Mac,一切正常。今天我遇到了一个全新的错误:

$ ruby -ropen-uri -e 'eval 

open("https://git.io/vQhWq").read'
Here's your Ruby and OpenSSL environment:

Ruby:           2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
RubyGems:       2.7.7
Bundler:        1.16.2
Compiled with:  OpenSSL 1.0.2o  27 Mar 2018
Loaded version: OpenSSL 1.0.2o  27 Mar 2018
SSL_CERT_FILE:  /usr/local/etc/openssl/cert.pem
SSL_CERT_DIR:   /usr/local/etc/openssl/certs

With that out of the way, let's see if you can connect to rubygems.org...

Bundler connection to rubygems.org:       failed  ❌  (execution expired)
RubyGems connection to rubygems.org:      success ✅
Ruby net/http connection to rubygems.org: success ✅

Although your Ruby installation and RubyGems can both connect to rubygems.org, Bundler is having trouble. The most likely way to fix this is to upgrade Bundler by running `gem install bundler`. Run this script again after doing that to make sure everything is all set. If you're still having trouble, check out the troubleshooting guide at http://ruby.to/ssl-check-failed 📦
(eval):136: warning: constant OpenSSL::SSL::SSLContext::METHODS is deprecated

然后我按照说明运行 $ gem install bundler,然后得到:

ERROR:  Could not find a valid gem 'bundler' (>= 0) in any repository

这是怎么回事?

最佳答案

对于 Mac OS,更改为以下配置即可。

System Preferences > Network > Advanced > TCP/IP > Configure IPv6: Link-local only

更多信息:https://rob.co.bb/posts/2018-10-22-yak-shave-gem-install-issue/

关于Ruby 无法连接到 ruby​​gems.org,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51201517/

相关文章:

ruby-on-rails - rails 控制台要求 nokogiri 返回 false(但在 irb 中工作)

ruby-on-rails - 在 Rails 中批量导入 CSV?

ruby - Ruby 中的数组哈希

ruby - 有没有包含大多数英语单词的 ruby​​ gem 或 API?

ruby-on-rails - 在 rails 3 中未发现 rake 任务

ruby - 为什么实例方法在include之后可以作为模块方法被调用?

ios - OpenSSL 从控制台命令到函数

python - Databricks 群集未初始化 Azure 库,错误为 : module 'lib' has no attribute 'SSL_ST_INIT'

hadoop - (cmake-compile) 项目 hadoop-common : make failed with error code 2

ruby-on-rails - 如何使用 Fish shell 为 gem 设置路径?