SSL_connect "unexpected message" 尝试连接到 OSX Big Sur 上的 ruby​​gems 时出错

SSL_connect "unexpected message" error trying to connect to rubygems on OSX Big Sur

我在 OSX Big Sur 上,出于某种原因,每当我通过 RVM 使用 ruby 二进制文件时,我都会得到:

Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=error: unexpected message (https://rubygems.org/specs.4.8.gz)

我已经尝试了这里的所有方法: https://bundler.io/v2.0/guides/rubygems_tls_ssl_troubleshooting_guide.html#troubleshooting-certificate-errors

SSL 检查期间 ($ curl -Lks 'https://git.io/rg-ssl' | ruby)

我很高兴

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

现在,当我删除 rvm 和 brew openssl 并重新安装 openssl 但仅通过 brew 安装 ruby ($ brew install ruby) 事情似乎工作。但是我无法以这种方式管理我的 ruby 二进制文件,所以我重新安装了 RVM,问题又回来了。

我假设我可以将 pem 文件添加到 /usr/local/etc/openssl@1.1/certs 文件夹,但是什么 pem?

在此处寻找一些 guidance/next 步骤。

更新

我认为这可能是 RVM 的问题,因为内置 ruby 没有问题。于是改用rbenv,问题依旧

安装并 Link 针对 OpenSSL,而不是 LibreSSL

Big Sur 附带 LibreSSL,一种非 OpenSSL 二进制文件。您可能必须:

brew install openssl@1.1

# Export flags for compiling against the keg-only OpenSSL library.
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

# Don't do this unless you really need to, as it will likely
# break some macOS native apps that depend on LibreSSL.
export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"

然后 rebuild/reinstall 您的 SSL 相关 Ruby 或宝石。根据您独特的配置,您可能还会遇到其他问题,但这应该可以解决 80% 的大多数相关问题。

已找到解决方案!

如果您想阅读解释,请访问他的网站:https://brettterpstra.com/2020/08/06/solving-rvm-and-openssl-issues-with-homebrew/

brew uninstall openssl --ignore-dependencies
brew tap-new $USER/old-openssl
brew extract --version=1.0.2t openssl $USER/old-openssl
brew install openssl@1.0.2t
brew install openssl
PKG_CONFIG_PATH=/usr/local/opt/openssl@1.0.2t/lib/pkgconfig \
rvm install 2.6.5 --with-openssl-dir=/usr/local/opt/openssl@1.0.2t

将 rvm 版本替换为您要使用的 ruby 版本

瞧瞧