gem or bundle fails: SSL verification error at depth 0, unable to get local issuer certificate
Your error
SSL verification error at depth 0: unable to get local issuer certificate (20)2 more lines it can showFix it fast
Most common cause, 1 of 4RubyGems or the operating system carries an outdated CA set
Update RubyGems and Bundler first; the RubyGems troubleshooting guide puts this step at the top, since current releases carry a fresh CA bundle for rubygems.org.
gem update --system
bundle update --bundler
sudo apt-get update && sudo apt-get install ca-certificatesShort answer
SSL verification error at depth 0: unable to get local issuer certificate (20) means RubyGems could not find the CA that issued the gem server's own certificate. Run bundle doctor ssl, then fix outdated RubyGems or OS certificates, a wrong clock, an untrusted proxy or private CA, or a server missing its intermediate (RubyGems 4.x).
Which cause do you have?
Let Bundler run its TLS diagnostic. It prints the OpenSSL version and CA setup Ruby uses and then connects to rubygems.org. If your own gem server is the one failing, point the check at it with --host.
bundle doctor ssl
bundle doctor ssl --host=gems.example.comThen find the line you see in this list and open its fix:
- 1RubyGems or the operating system carries an outdated CA set
bundle doctor ssl fails even for rubygems.org, typically on an old machine, image or Ruby install - 2The machine's clock is far from the real time
The failure starts on a fresh VM, in a container or after a laptop resumes, and other HTTPS tools complain too - 3A proxy or private CA signs the certificate you receive
It fails only on the office network or VPN, or only for an internal gem server, and the issuer is not a public CA - 4Your own gem server sends its certificate without the intermediate
rubygems.org passes, but a private server fails with error 20 at depth 0 on machines whose CA store is current
What does the error look like?
SSL verification error at depth 0: unable to get local issuer certificate (20)You must add /C=US/O=Example Corp/CN=Example Corp Issuing CA to your local trusted storeOpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: certificate verify failed
Cause 1 of 4
RubyGems or the operating system carries an outdated CA set
You seebundle doctor ssl fails even for rubygems.org, typically on an old machine, image or Ruby install
Check
Error 20 at depth 0 against rubygems.org itself means the CA set Ruby trusts is too old to contain the root the server chains to. RubyGems builds its store from OpenSSL's default paths, which the OS or the Ruby build provides, and adds the CA files it ships for rubygems.org.
gem --version
bundle --versionFix
Update RubyGems and Bundler first; the RubyGems troubleshooting guide puts this step at the top, since current releases carry a fresh CA bundle for rubygems.org. If the failure stays, refresh the OS certificate package.
gem update --system
bundle update --bundler
sudo apt-get update && sudo apt-get install ca-certificatesVerify
bundle doctor ssl finishes without a verification error.
bundle doctor sslConfirmed by guides.rubygems.org
Cause 2 of 4
The machine's clock is far from the real time
You seeThe failure starts on a fresh VM, in a container or after a laptop resumes, and other HTTPS tools complain too
Check
A gem SSL verification error that starts on a fresh VM or container often comes from a clock that is badly off. The RubyGems guide asks you to compare the system time with a reliable source, because wrong time makes valid certificates look expired or not yet valid.
date -u
timedatectl statusFix
Correct the time if it is off by more than a few minutes and switch on automatic synchronisation, as the guide recommends.
sudo timedatectl set-ntp trueVerify
timedatectl shows the clock as synchronised, and the gem install that failed goes through.
gem install rakeConfirmed by guides.rubygems.org
Cause 3 of 4
A proxy or private CA signs the certificate you receive
You seeIt fails only on the office network or VPN, or only for an internal gem server, and the issuer is not a public CA
Check
Error 20 on the office network or for an internal gem server means a proxy or private CA signed the certificate and Ruby does not trust it. Print the issuer that actually reaches you; RubyGems also names it in the line You must add ... to your local trusted store, which it prints for error 20.
openssl s_client -connect rubygems.org:443 -servername rubygems.org </dev/null 2>/dev/null | openssl x509 -noout -issuerFix
Ask your IT team for the root certificate in PEM form and set ssl_ca_cert in .gemrc to its path. RubyGems documents the option as the path of a directory or file of CA certificates used for remote HTTPS connections, and adds it to its store.
# ~/.gemrc
:ssl_ca_cert: /etc/ssl/corp/company-root.pemVerify
Repeat the command that failed.
gem install rakeConfirmed by raw.githubusercontent.com
Cause 4 of 4
Your own gem server sends its certificate without the intermediate
You seerubygems.org passes, but a private server fails with error 20 at depth 0 on machines whose CA store is current
Check
Error 20 at depth 0 from a private gem server, on machines with a current CA store, means the server sends its leaf without the intermediate. Clients then cannot find the issuer of that first certificate. s_client with -showcerts lists exactly what the server sends, in order.
openssl s_client -connect gems.example.com:443 -servername gems.example.com -showcerts </dev/nullFix
On the server, concatenate the server certificate first and the CA's intermediate bundle after it, and load that file. nginx documents this exact order for its ssl_certificate file.
cat gems.example.com.crt bundle.crt > gems.example.com.chained.crt
# nginx: ssl_certificate /etc/ssl/gems.example.com.chained.crt;Verify
-showcerts lists more than one certificate, and the doctor run against that host passes.
bundle doctor ssl --host=gems.example.comConfirmed by nginx.org
How do I stop it coming back?
- Run gem update --system in base images and on build machines on a schedule, so the bundled rubygems.org CA set stays current.
- Bake the company root into the image and set ssl_ca_cert there, instead of patching developer laptops one by one.
- Add bundle doctor ssl --host=<your gem server> to the CI image check, so a broken chain fails before a deploy.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.