无法验证https://rubygems.org/的SSL证书。

20

当我运行bundle install时,出现了以下错误:

Could not verify the SSL certificate for https://rubygems.org/.
There is a chance you are experiencing a man-in-the-middle attack, but most likely 
your system doesn't have the CA certificates needed for verification. For
information about OpenSSL certificates, see bit.ly/ruby-ssl. To connect without using 
SSL, edit your Gemfile sources and change 'https' to 'http'.

然而,这只发生在我的一个项目中,并且似乎只有我遇到了这个问题。此外,我可以通过运行bundle update来解决它,在那里我不会遇到这个错误,并且之后可以继续进行。

是否有什么东西没有被项目跟踪(只存在于我的机器上),我已经配置错误了吗?


5
尝试输入以下命令:gem update --system,如果你在MAC上,请尝试输入rvm osx-ssl-certs update - Nobita
还要检查您的系统是否具有正确的日期/时间。(例如,如果它是虚拟机,则如果您挂起主机,则可能会丢失时间。) - crestor
8个回答

26
我在Mac OS X Yosemite使用ruby 2.3.1时遇到了这个问题。我通过下载http://curl.haxx.se/ca/cacert.pem并将其放置于/usr/local/etc/openssl/中来解决该问题。
然后,我在.bash_profile中添加了以下行:export SSL_CERT_FILE=/usr/local/etc/openssl/cacert.pem 感谢Can't run Ruby 2.2.3 with RVM on OSX的帮助,但是要找到正确答案还是很难的,因此我将其添加到了这个页面。

2
如果对于Zsh用户来说不是很明显,那么请将导出行添加到.zshrc文件中。 - userFriendly
由于得到了赞同(而且我的解决方案已经有5年历史),我更新了这个更好的答案。 - cdpalmer
这个解决方案对我也起作用了。适用于Mac OSX BigSur,Ruby 2.6.4和RVM 1.29.7(1.29.7)。 - Sohair Ahmad

12

5

gem update --system 对我有效


3
对于 Linux 用户,只需安装包:ca-certificates

这对我解决了问题,在Ubuntu 18.04.1上使用rbenv - Mikel

2

由于我使用的是rbenv而不是rvm,因此我无法使用大多数在线解决方案。

通过卸载并重新安装openssl,我成功解决了这个问题。

一切都好了,但我不确定为什么。


1
这里也有一个好的解决方案:https://dev59.com/M2Ik5IYBdhLWcg3wku9n - 23tux
1
不要尝试这个,伙计。我的大部分依赖包都被删除了。 - rejin

1

升级openssl应该可以解决这个问题。(如果是MacOSX)

brew upgrade openssl

1

我使用OSX 10.14.6和Rails 6,以下方法适用于我:

rvm osx-ssl-certs update


-3

或许这个方法会有用

1.将源切换到https://gems.ruby-china.org/

$ gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/

2. 检查当前源代码

$ gem sources -l

*** CURRENT SOURCES ***

https://gems.ruby-china.org

3. 镜像宝石源

$ bundle config mirror.https://rubygems.org https://gems.ruby-china.org

通过这些方法,您将不需要更改Gemfile souce

希望这个方法对您有用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接