首页 > 解决方案 > 安装 cocoapods 时出现 SSL 验证错误

问题描述

我做了什么sudo gem install cocoapods

这是来自终端的完整消息

ERROR:  You must add /C=BE/O=GlobalSign nv-sa/CN=AlphaSSL CA - SHA256 - G2 to your local trusted store
ERROR:  Could not find a valid gem 'cocoapods' (>= 0), here is why:
          Unable to download data from https://rubygems.org/ - hostname "rubygems.org" does not match the server certificate (https://rubygems.org/specs.4.8.gz)
ERROR:  SSL verification error at depth 0: unable to get local issuer certificate (20)

我没有使用 SSL 的经验,但我遵循了几个与我类似的问题,但没有运气

我试过的:

标签: rubysslcocoapods

解决方案


MichaelHuelsen 有正确的答案。在这里,我将给出对我有用的分步说明,但会用一个大文件覆盖 pem 文件,因此请注意,如果其中包含您可能不想破坏的敏感信息。

  1. 识别证书文件。
$ ruby -ropenssl -e 'p OpenSSL::X509::DEFAULT_CERT_FILE'
"/etc/pki/tls/cert.pem"

告诉我我的证书文件在哪里。

  1. 备份证书文件
cp /etc/pki/tls/cert.pem /tmp/cert.pem.bak
  1. 通过 curl 复制完整的证书文件

见:https ://curl.se/docs/caextract.html

curl --remote-name --time-cond cacert.pem https://curl.se/ca/cacert.pem
  1. 移动新的 cacert.pem 文件以替换旧文件
mv cacert.pem /etc/pki/tls/cert.pem

然后我跑去gem update --system更新东西,但你可能只是可以运行你原来的gem命令。


推荐阅读