简体   繁体   English

软件包安装失败,并显示SSL证书验证错误

[英]bundle install fails with SSL certificate verification error

When I run bundle install for my Rails 3 project on Centos 5.5 it fails with an error: 当我在Centos 5.5上为Rails 3项目运行bundle install ,它失败并出现错误:

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.

When I try to install the gem manually (by gem install multi_json -v '1.3.2' ) it works. 当我尝试手动安装gem时(通过gem install multi_json -v '1.3.2' ),它可以工作。 The same problem occurs with several other gems. 其他几个宝石也会发生相同的问题。 I use RVM (1.12.3), ruby 1.9.2, bundler 1.1.3. 我使用RVM(1.12.3),ruby 1.9.2,bundler 1.1.3。

How to fix it? 如何解决?

Update 更新资料

Now that I've karma wh..err mined enough from this answer everyone should know that this should have been fixed. 现在,我已经从这个答案中充分挖掘了..err,每个人都应该知道应该已经解决了这个问题。

re: via Ownatik again bundle install fails with SSL certificate verification error 重新:通过Ownatik再次捆绑安装失败,出现SSL证书验证错误

gem update --system

My answer is still correct and left below for reference if that ends up not working for you. 我的答案仍然是正确的,如果最终对您不起作用,请留在下面以供参考。


Honestly the best temporary solution is to 老实说,最好的临时解决方案是

[...] use the non-ssl version of rubygems in your gemfile as a temporary workaround. [...]在您的gemfile中使用rubygems的非SSL版本作为临时解决方法。

via user Ownatik 通过用户Ownatik

what they mean is at the top of the Gemfile in your rails application directory change 它们的意思是在Rails应用程序目录更改中Gemfile的顶部

source 'https://rubygems.org'

to

source 'http://rubygems.org'

note that the second version is http instead of http s 需要注意的是第二个版本是http而不是http 小号

Replace the ssl gem source with non-ssl as a temp solution: 将ssl gem源替换为non-ssl作为临时解决方案:

The reason is old rubygems. 原因是古老的红宝石。 You need to update system part using non ssl source first: 您需要首先使用非SSL源更新系统部件:

gem update --system --source http://rubygems.org/ (temporarily updating system part using non-ssl connection). gem update --system --source http://rubygems.org/ (使用非SSL连接临时更新系统部件)。

Now you're ready to use gem update . 现在您可以使用gem update

如果您使用的是Mac,并且使用的是RVM的最新版本(〜1.20),则以下命令对我有用。

rvm osx-ssl-certs update

This issue should now be fixed. 现在应该解决此问题。 Update rubygems ( gem update --system ), make sure openssl is at the latest version on your OS, or try these tips of it's still not working: http://railsapps.github.com/openssl-certificate-verify-failed.html 更新rubygems( gem update --system ),确保openssl是您操作系统上的最新版本,或者尝试以下仍不能使用的提示: http : //railsapps.github.com/openssl-certificate-verify-failed。 html

Temporary solution (as alluded to by Ownatik): 临时解决方案(由Ownatik暗示):

Create or modify a file called .gemrc in your home path, including the line :ssl_verify_mode: 0 在您的主路径中创建或修改一个名为.gemrc的文件,包括:ssl_verify_mode: 0

This will prevent bundler from checking the SSL certificates of gems when it attempts to install them. 这将防止捆绑程序在尝试安装gem时检查其SSL证书。

For *nix devices, 'home path' means ~/.gemrc . 对于* nix设备,“主路径”表示~/.gemrc You can also create /etc/gemrc if you prefer. 如果愿意,还可以创建/etc/gemrc For Windows XP, 'home path' means c:\\Documents and Settings\\All Users\\Application Data\\gemrc . 对于Windows XP,“主路径”表示c:\\Documents and Settings\\All Users\\Application Data\\gemrc For Windows 7, C:\\ProgramData\\gemrc 对于Windows 7, C:\\ProgramData\\gemrc

On windows7 you can download the cacert.pem file from here and set the environementvariable SSL_CERT_FILE to the path where you store the certificate eg 在Windows7上,您可以从此处下载cacert.pem文件,并将环境变量SSL_CERT_FILE设置为存储证书的路径,例如

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

or you can set the variable in your script like this ENV['SSL_CERT_FILE']="C:/users/<username>/cacert.pem" 或者您可以在脚本中设置变量,例如ENV['SSL_CERT_FILE']="C:/users/<username>/cacert.pem"

Replace <username> with you own username. 将<username>替换为您自己的用户名。

The real solution to this problem, if you are using RVM: 如果使用的是RVM,则此问题的真正解决方案是:

  1. Update rubygems: gem update --system 更新rubygems: gem update --system
  2. Use RVM to refresh SSL certs: rvm osx-ssl-certs update all 使用RVM刷新SSL证书: rvm osx-ssl-certs update all

Hat tip to this tip on the RailsApps project ! 在RailsApps项目上的提示

For those of you that have ruby installed through RVM and want a quick fix (preferring not to read per Bruno's request) just try this: 对于那些通过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

For a more details, here is the link where I found the solution. 有关更多详细信息,这是我找到解决方案的链接。

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

BTW, I didn't have to touch my certificates on Ubuntu. 顺便说一句,我不必在Ubuntu上接触我的证书。

Best of all, this isn't a workaround. 最棒的是,这不是解决方法。 It will download gems through SSL and fail if there if there is a problem like a man in the middle attack which is much better than just turning off security. 它将通过SSL下载gem,如果出现类似中间人攻击的问题,则该失败将失败,这比关闭安全性要好得多。

You can download a list of CA certificates from curl's website at http://curl.haxx.se/ca/cacert.pem 您可以从curl的网站上下载CA证书列表,网址为http://curl.haxx.se/ca/cacert.pem

Then set the SSL_CERT_FILE environment variable to tell Ruby to use it. 然后设置SSL_CERT_FILE环境变量以告诉Ruby使用它。 For example, in Linux: 例如,在Linux中:

$ SSL_CERT_FILE=~/cacert.pem bundle install

(Reference: https://gist.github.com/fnichol/867550 ) (参考: https : //gist.github.com/fnichol/867550

This has been fixed 该问题已解决

http://guides.rubygems.org/ssl-certificate-update/ http://guides.rubygems.org/ssl-certificate-update/

Now that RubyGems 2.6.x has been released, you can manually update to this version. 现在RubyGems 2.6.x已发布,您可以手动更新到该版本。

Download https://rubygems.org/downloads/rubygems-update-2.6.7.gem 下载https://rubygems.org/downloads/rubygems-update-2.6.7.gem

Please download the file in a directory that you can later point to (eg. the root of your harddrive C:) 请将该文件下载到以后可以指向的目录中(例如,硬盘C的根目录:)

Now, using your Command Prompt: 现在,使用命令提示符:

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

After this, gem --version should report the new update version. 此后,gem --version应该报告新的更新版本。

You can now safely uninstall rubygems-update gem: 您现在可以安全地卸载rubygems-update gem:

C:\>gem uninstall rubygems-update -x

Simple copy paste instruction given here about .pem file 此处提供有关.pem文件的简单复制粘贴指令

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

For certificate verification failed 证书验证失败

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 . 我们需要下载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. C:> gem其中的rubygems C:/Ruby21/lib/ruby/2.1.0/rubygems.rb现在,让我们找到该目录。 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. C:>启动C:\\ Ruby21 \\ lib \\ ruby​​ \\ 2.1.0 \\ ruby​​gems这将在我们指定的目录内打开一个Explorer窗口。

Step 3: Copy new trust certificate 步骤3:复制新的信任证书

Now, locate ssl_certs directory and copy the .pem file we obtained from previous step inside. 现在,找到ssl_certs目录并复制从上一步中获得的.pem文件。

It will be listed with other files like GeoTrustGlobalCA.pem. 它将与其他文件(如GeoTrustGlobalCA.pem)一起列出。

same problem but with different gem here: 同样的问题,但是这里有不同的宝石:

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

temporarily solution: gem install builder -v '3.0.0' makes it possible to continue bundle install 临时解决方案: gem install builder -v '3.0.0'使继续bundle install成为可能

The simplest solution: 最简单的解决方案:

rvm pkg install openssl
rvm reinstall all --force

Voila! 瞧!

This is How you fix this problem on Windows: 这是在Windows上解决此问题的方法:

download .perm file then set the SSL_CERT_FILE in command prompt 下载.perm文件,然后在命令提示符下设置SSL_CERT_FILE

https://gist.github.com/fnichol/867550 https://gist.github.com/fnichol/867550

I get a slightly different error, though perhaps related, on Ubuntu 12.04: 在Ubuntu 12.04上,我得到了一个稍微不同的错误,尽管可能与之相关:

Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=unknown state: sslv3 alert handshake failure (https://d2chzxaqi4y7f8.cloudfront.net/gems/activesupport-3.2.3.gem)
An error occured while installing activesupport (3.2.3), and Bundler cannot continue.
Make sure that `gem install activesupport -v '3.2.3'` succeeds before bundling.

It happens when I run bundle install with source 'https://rubygems.org' in a Gemfile. 当我在Gemfile中使用source 'https://rubygems.org'运行bundle install时,就会发生这种情况。

This is an issue with OpenSSL on Ubuntu 12.04. 这是Ubuntu 12.04上的OpenSSL问题。 See Rubygems issue #319 . 参见Rubygems问题#319

To fix this, run apt-get update && apt-get upgrade on Ubuntu 12.04 to upgrade your OpenSSL. 要解决此问题,请在Ubuntu 12.04上运行apt-get update && apt-get upgrade升级OpenSSL。

I was able to track this down to the fact that the binaries that rvm downloads do not play nice with OS X's OpenSSL, which is old and is no longer used by the OS. 我可以rvm下载的二进制文件不能在OS X的OpenSSL上很好地使用的事实,因为OpenSSL是旧的并且不再被OS使用。

The solution for me was to force compilation when installing Ruby via rvm : 对我来说,解决方案是在通过rvm安装Ruby时强制编译:

rvm reinstall --disable-binary 2.2

My permanent fix for Windows: 我对Windows的永久修复:

  1. Download the CACert , save as C:\\ruby\\ssl_certs\\GlobalSignRootCA.pem from http://guides.rubygems.org/ssl-certificate-update/ http://guides.rubygems.org/ssl-certificate-update/下载CACert ,另存为C:\\ruby\\ssl_certs\\GlobalSignRootCA.pem

  2. Create system variable named " SSL_CERT_FILE ", set to C:\\ruby\\ssl_certs\\GlobalSignRootCA.pem . 创建名为“ SSL_CERT_FILE ”的系统变量,并将其设置为C:\\ruby\\ssl_certs\\GlobalSignRootCA.pem

  3. Try again: gem install bundler : 再试一次: gem install bundler

 C:\\gem sources *** CURRENT SOURCES *** https://rubygems.org/ C:\\gem install bundler Fetching: bundler-1.13.5.gem (100%) Successfully installed bundler-1.13.5 1 gem installed 

Thx to @Alexander.Iljushkin for: 感谢@ Alexander.Iljushkin:

gem update --system --source http://rubygems.org/

After that bundler still failed and the solution to that was: 在那个捆绑器仍然失败之后,解决方案是:

gem install bundler

I was getting a similar error. 我遇到了类似的错误。 Here is how I solved this: In your path directory, check for Gemfile. 这是我解决此问题的方法:在您的路径目录中,检查Gemfile。 Edit the source in the gemfile to http instead of https and save it. 将gemfile中的源代码编辑为http而不是https并保存。 This might install the bundler without the SSL certificate issue.l 这可能会安装捆绑程序而没有SSL证书问题。

For Windows machine, check your gem version with 对于Windows计算机,请使用以下命令检查您的gem版本

gem --version

Then update your gem as follow: 然后按照以下步骤更新您的gem:

Please download the file in a directory that you can later point to (eg. the root of your hard drive C:) 请将该文件下载到以后可以指向的目录中(例如,硬盘C:的根目录)

Now, using your Command Prompt: 现在,使用命令提示符:

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

Now, bundle install will success without SSL certificate verification error. 现在,捆绑安装将成功完成,而不会出现SSL证书验证错误。

More detailed instruction is here 更详细的说明在这里

This worked for me: 这对我有用:

  • download latest gem at https://rubygems.org/pages/download https://rubygems.org/pages/download下载最新的gem
  • install the gem with gem install --local [path to downloaded gem file] 使用gem install --local [path to downloaded gem file]
  • update the gems with update_rubygems 使用update_rubygems更新gem
  • check that you're on the latest gem version with gem --version 使用gem --version检查您是否在最新的gem版本上

I had to reinstall openssl: 我不得不重新安装openssl:

brew uninstall --force openssl
brew install openssl

I was just recently faced with this issue and followed the steps outlined here . 我刚遇到这个问题,并按照此处概述的步骤进行操作。 There might be a chance that you are not pointing to the right OpenSSL certificate. 您可能没有指向正确的OpenSSL证书。 After running: 运行后:

rvm osx-ssl-certs status all
rvm osx-ssl-certs update all

and

export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt

the bundle complete ran! 捆绑完成了!

Download rubygems-update-2.6.7.gem . 下载rubygems-update-2.6.7.gem

Now, using your Command Prompt: 现在,使用命令提示符:

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

After this, gem --version should report the new update version. 此后, gem --version应该报告新的更新版本。

You can now safely uninstall rubygems-update gem: 您现在可以安全地卸载rubygems-update gem:

C:\>gem uninstall rubygems-update -x
Removing update_rubygems
Successfully uninstalled rubygems-update-2.6.7

To note, if you're grabbing gems from a source which SSL cert is trusted by an internal certificate authority (or you are connecting to an external source through a company web proxy with SSL inspection), point your SSL_CERT_FILE env variable to your certificate chain. 请注意,如果您要从内部证书颁发机构信任SSL证书的来源中获取宝石(或者正在通过具有SSL检查的公司Web代理连接到外部来源),请将SSL_CERT_FILE env变量指向证书链。 This most likely just requires exporting your root certificate from your certificate store (System Keychain on macOS) to an accessible location from your shell ie: 这很可能只需要将您的根证书从证书存储(macOS上的系统钥匙串)导出到您的Shell可以访问的位置,即:

export SSL_CERT_FILE=~/RootCert.pem

If you're using rails-assets 如果您正在使用rails-assets

If you were using https://rails-assets.org/ to manage your assets, no answers will help you. 如果您使用https://rails-assets.org/来管理资产,那么没有答案会帮助您。 Even converting to http won't help. 即使转换为http也无济于事。

The simplest fix is using this source instead, http://insecure.rails-assets.org . 最简单的修复方法是使用此资源http://insecure.rails-assets.org This has been mentioned in their homepage . 这已经在他们的主页中提到了。

The only thing that worked for me on legacy windows system and ruby 1.9 version is downloading cacert file from http://guides.rubygems.org/ssl-certificate-update/ 对我来说,在旧版Windows系统和ruby 1.9版本上唯一起作用的是从http://guides.rubygems.org/ssl-certificate-update/下载cacert文件

And then running below command before running bundle install 然后在运行捆绑安装之前运行以下命令

bundle config --global ssl_ca_cert /path/to/file.pem

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM