Rails Windows 下 Bundler::Fetcher::CertificateFailureError 出错的解决办法

dayudodo · 2017年11月13日 · 最后由 dayudodo 回复于 2017年11月13日 · 3266 次阅读

安装新版本的 railsInstaller5.1.4 一切正常,等到 bundle install 的时候出现了这样的错误:

Retrying fetcher due to error (2/4): Bundler::Fetcher::CertificateFailureError Could not verify the SSL certificate for https://gems.ruby-china.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 http://bit.ly/ruby-ssl. To connect without using SSL, edit your Gemfile sources and change 'https' to 'http'.

google 后发现解决办法,需要个 carcert.pem 的文件,可以用下面的脚本自动下载此文件并加载到当前环境中,请先创建一个目录名称为:C:\RailsInstaller

require 'net/http'

# create a path to the file "C:\RailsInstaller\cacert.pem"
cacert_file = File.join(%w{c: RailsInstaller cacert.pem})

Net::HTTP.start("curl.haxx.se") do |http|
  resp = http.get("/ca/cacert.pem")
  if resp.code == "200"
    open(cacert_file, "wb") { |file| file.write(resp.body) }
    puts "\n\nA bundle of certificate authorities has been installed to"
    puts "C:\\RailsInstaller\\cacert.pem\n"
    puts "* Please set SSL_CERT_FILE in your current command prompt session with:"
    puts "     set SSL_CERT_FILE=C:\\RailsInstaller\\cacert.pem"
    puts "* To make this a permanent setting, add it to Environment Variables"
    puts "  under Control Panel -> Advanced -> Environment Variables"
  else
    abort "\n\n>>>> A cacert.pem bundle could not be downloaded."
  end
end

永久的解决办法是把变量 SSL_CERT_FILE 添加到环境变量中,如图:

或者你自己手动下载 carcert.pem 文件并设置好环境变量 (http://curl.haxx.se/ca/cacert.pem), 本文代码及方法参考自:(https://gist.github.com/fnichol/867550)

不要在 windows 下跑 Rails😂

zhangzitao 回复

其实只是想看看 windows 下能否跑起来,开发还是用的 mac 系统

需要 登录 后方可回复, 如果你还没有账号请 注册新账号