Ruby-on-rails 捆绑安装失败并显示 SSL 证书验证错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10246023/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
bundle install fails with SSL certificate verification error
提问by mrzasa
When I run bundle installfor my Rails 3 project on Centos 5.5 it fails with an error:
当我bundle install在 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.
When I try to install the gem manually (by gem install multi_json -v '1.3.2') it works. The same problem occurs with several other gems. I use RVM (1.12.3), ruby 1.9.2, bundler 1.1.3.
当我尝试手动(通过gem install multi_json -v '1.3.2')安装 gem 时,它可以工作。其他几个宝石也会出现同样的问题。我使用 RVM (1.12.3)、ruby 1.9.2、bundler 1.1.3。
How to fix it?
如何解决?
回答by Will
Update
更新
Now that I've karma wh..err mined enough from this answer everyone should know that this should have been fixed.
既然我已经从这个答案中挖掘了足够的业力,每个人都应该知道这应该已经解决了。
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 中使用非 ssl 版本的 rubygems 作为临时解决方法。
via user Ownatik
通过用户 Ownatik
what they mean is at the top of the Gemfilein your rails application directory change
它们的意思是在GemfileRails 应用程序目录更改的顶部
source 'https://rubygems.org'
source 'https://rubygems.org'
to
到
source 'http://rubygems.org'
source 'http://rubygems.org'
note that the second version is http instead of https
请注意,第二个版本是 http 而不是 http s
回答by StuR
Replace the ssl gem source with non-ssl as a temp solution:
将 ssl gem 源替换为非 ssl 作为临时解决方案:
- gem sources -r https://rubygems.org/
- gem sources -a http://rubygems.org/
- gem 源 -r https://rubygems.org/
- 宝石来源 -a http://rubygems.org/
回答by Alexander.Iljushkin
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.
回答by chaserx
If you're on a mac and use a recent version of RVM (~1.20), the following command worked for me.
如果您使用的是 mac 并使用最新版本的 RVM (~1.20),则以下命令对我有用。
rvm osx-ssl-certs update
回答by fbernier
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
回答by asfallows
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.
这将阻止 bundler 在尝试安装 gems 时检查它们的 SSL 证书。
For *nix devices, 'home path' means ~/.gemrc. You can also create /etc/gemrcif you prefer. For Windows XP, 'home path' means c:\Documents and Settings\All Users\Application Data\gemrc. For Windows 7, C:\ProgramData\gemrc
对于 *nix 设备,“主路径”表示~/.gemrc. /etc/gemrc如果您愿意,也可以创建。对于 Windows XP,“主路径”是指c:\Documents and Settings\All Users\Application Data\gemrc. 对于 Windows 7,C:\ProgramData\gemrc
回答by peter
On windows7 you can download the cacert.pem file from hereand 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> 替换为您自己的用户名。
回答by Alan H.
The real solution to this problem, if you are using RVM:
这个问题的真正解决方案,如果你使用的是 RVM:
- Update rubygems:
gem update --system - Use RVM to refresh SSL certs:
rvm osx-ssl-certs update all
- 更新 rubygems:
gem update --system - 使用 RVM 刷新 SSL 证书:
rvm osx-ssl-certs update all
Hat tip to this tip on the RailsApps project!
帽尖到这个技巧在RailsApps项目!
回答by arcanex
You can download a list of CA certificates from curl's website at http://curl.haxx.se/ca/cacert.pem
您可以从 curl 的网站http://curl.haxx.se/ca/cacert.pem下载 CA 证书列表
Then set the SSL_CERT_FILE environment variable to tell Ruby to use it. For example, in Linux:
然后设置 SSL_CERT_FILE 环境变量以告诉 Ruby 使用它。例如,在 Linux 中:
$ SSL_CERT_FILE=~/cacert.pem bundle install
(Reference: https://gist.github.com/fnichol/867550)
回答by danielrussia
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 并想要快速修复(不想按照布鲁诺的要求阅读)的人,请尝试以下操作:
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 下载 gems,如果出现中间人攻击这样的问题,它会失败,这比关闭安全性要好得多。

