Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tranductam2802/85e9301d63d492abf39151b0d6e3db62 to your computer and use it in GitHub Desktop.
Save tranductam2802/85e9301d63d492abf39151b0d6e3db62 to your computer and use it in GitHub Desktop.
Are you getting an error “OpenSSL certificate verify failed” with Ruby? You may be seeing Ruby errors with OpenSSL because of outdated SSL certificate files. These problems are most common with Ruby 2.1 on Mac OS X.

OpenSSL Errors and Rails – Certificate Verify Failed

Errors overviews

The error message:

openssl::ssl::sslerror: ssl_connect returned=1 errno=0 state=sslv3 read server certificate b: certificate verify failed

or

could not load openssl. you must recompile ruby with openssl support or change the sources in your gemfile from 'https' to 'http'. instructions for compiling with openssl using rvm are available at rvm.io/packages/openssl.

or

ERROR: Could not find a valid gem 'rails' (= 5.2.1), here is why: Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: tlsv1 alert protocol version (https://rubygems.org/specs.4.8.gz)

How to fixed?

Use RVM to Fix SSL Certificates

Using the RVM (Ruby Version Manager), whichs include a utility to diagnose and resolve errors caused by outdated certificate files.

$ rvm -v
# rvm 1.29.4 (stable)
$ rvm osx-ssl-certs status all
# Certificates for...
$ rvm osx-ssl-certs update all
# Updating certificates...

When the certificate files again become outdated, the error may reappear. To keep the certificate files current, RVM offers an option to run a cron job that updates the certificate files daily.

$ sudo rvm osx-ssl-certs cron install

Update SSL Certificates

The SSL certificates that comes with Mac OS X 10.8 may be outdated. You can install Homebrew and try this:

$ brew update
$ brew install openssl
$ brew link openssl --force
$ brew install curl-ca-bundle
$ brew tap raggi/ale
$ brew install openssl-osx-ca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment