当我在Centos 5.5上为我的Rails 3项目运行捆绑安装时,它失败了,出现了一个错误:

Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3 
read server certificate B: certificate verify failed 
(https://bb-m.rubygems.org/gems/multi_json-1.3.2.gem)
An error occured while installing multi_json (1.3.2), and Bundler cannot continue.
Make sure that `gem install multi_json -v '1.3.2'` succeeds before bundling.

当我尝试手动安装gem(通过gem install multi_json -v '1.3.2')它工作。同样的问题也发生在其他宝石上。我使用RVM (1.12.3), ruby 1.9.2, bundle 1.1.3。

如何解决?


当前回答

在windows7上可以下载cacert。将环境变量SSL_CERT_FILE设置为您存储证书的路径

SET SSL_CERT_FILE="C:\users\<username>\cacert.pem"

或者你可以在脚本中这样设置变量ENV['SSL_CERT_FILE']="C:/users/<username>/cacert.pem"

将<username>替换为您自己的用户名。

其他回答

临时解决方案(Ownatik提到的):

在主路径中创建或修改一个名为.gemrc的文件,包括:ssl_verify_mode: 0这一行

这将防止捆绑程序在试图安装宝石时检查宝石的SSL证书。

对于*nix设备,'home path'意味着~/.gemrc。如果愿意,也可以创建/etc/gemrc。对于Windows XP,“home path”的意思是c:\Documents and Settings\All Users\Application Data\gemrc。对于Windows 7, C:\ProgramData\gemrc

对于那些通过RVM安装了ruby并想要快速修复的人(更喜欢不按Bruno的要求阅读),请尝试以下方法:

rvm remove 1.9.x (or whatever version of ruby you are using)
rvm pkg install openssl
rvm install 1.9.2 --with-openssl-dir=$rvm_path/usr

要了解更多细节,这里是我找到解决方案的链接。

http://railsapps.github.com/openssl-certificate-verify-failed.html

顺便说一句,我在Ubuntu上不需要修改我的证书。

最重要的是,这不是一个变通办法。它将下载宝石通过 SSL和失败,如果有如果有一个人在中间的问题 这比关闭安全系统强多了。

我对Windows的永久修复:

下载CACert,保存为C:\ruby\ssl_certs\GlobalSignRootCA。Pem来自http://guides.rubygems.org/ssl-certificate-update/ 创建名为“SSL_CERT_FILE”的系统变量,设置为C:\ruby\ssl_certs\GlobalSignRootCA.pem。 重试:gem安装bundle:

C: \宝石来源 ***当前来源*** https://rubygems.org/ C:\gem安装捆绑器 抓取:bundler-1.13.5。宝石(100%) 成功安装bundle -1.13.5 安装1个宝石

对于Windows机器,检查您的gem版本

gem --version

然后更新你的宝石如下:

1.8运行。X:下载1.8.30 2.0运行。X:下载2.0.15 2.2运行。X:下载2.2.3

请将该文件下载到您稍后可以指向的目录中(例如。你的硬盘的根目录C:)

现在,使用命令提示符:

C:\>gem install --local C:\rubygems-update-1.8.30.gem
C:\>update_rubygems --no-ri --no-rdoc

现在,bundle安装将成功,没有SSL证书验证错误。

更详细的说明在这里

简单的复制粘贴指令这里给出关于.pem文件

https://gist.github.com/luislavena/f064211759ee0f806c88

证书验证失败

If you've read the previous sections, you will know what this means (and shame > on you if you have not). We need to download AddTrustExternalCARoot-2048.pem. Open a Command Prompt and type in: C:>gem which rubygems C:/Ruby21/lib/ruby/2.1.0/rubygems.rb Now, let's locate that directory. From within the same window, enter the path part up to the file extension, but using backslashes instead: C:>start C:\Ruby21\lib\ruby\2.1.0\rubygems This will open a Explorer window inside the directory we indicated. Step 3: Copy new trust certificate Now, locate ssl_certs directory and copy the .pem file we obtained from previous step inside. It will be listed with other files like GeoTrustGlobalCA.pem.