Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

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 show

Fix it fast

Most common cause, 1 of 4

RubyGems 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.

Fix
gem update --system
bundle update --bundler
sudo apt-get update && sudo apt-get install ca-certificates
Did this fix it?
Full steps for this cause: check, fix, verify

Short 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).

  • Applies to Ruby 3.4, Ruby 4.0, RubyGems 4.1, Bundler 4.1, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

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.

Run this first
bundle doctor ssl
bundle doctor ssl --host=gems.example.com

Then find the line you see in this list and open its fix:

  1. 1RubyGems or the operating system carries an outdated CA setbundle doctor ssl fails even for rubygems.org, typically on an old machine, image or Ruby install
  2. 2The machine's clock is far from the real timeThe failure starts on a fresh VM, in a container or after a laptop resumes, and other HTTPS tools complain too
  3. 3A proxy or private CA signs the certificate you receiveIt fails only on the office network or VPN, or only for an internal gem server, and the issuer is not a public CA
  4. 4Your own gem server sends its certificate without the intermediaterubygems.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 store
  • OpenSSL::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.

Check
gem --version
bundle --version

Fix

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.

Fix
gem update --system
bundle update --bundler
sudo apt-get update && sudo apt-get install ca-certificates

Verify

bundle doctor ssl finishes without a verification error.

Verify
bundle doctor ssl

Confirmed by guides.rubygems.org

Did this fix it?

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.

Check
date -u
timedatectl status

Fix

Correct the time if it is off by more than a few minutes and switch on automatic synchronisation, as the guide recommends.

Fix
sudo timedatectl set-ntp true

Verify

timedatectl shows the clock as synchronised, and the gem install that failed goes through.

Verify
gem install rake

Confirmed by guides.rubygems.org

Did this fix it?

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.

Check
openssl s_client -connect rubygems.org:443 -servername rubygems.org </dev/null 2>/dev/null | openssl x509 -noout -issuer

Fix

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.

Fix
# ~/.gemrc
:ssl_ca_cert: /etc/ssl/corp/company-root.pem

Verify

Repeat the command that failed.

Verify
gem install rake

Confirmed by raw.githubusercontent.com

Did this fix it?

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.

Check
openssl s_client -connect gems.example.com:443 -servername gems.example.com -showcerts </dev/null

Fix

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.

Fix
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.

Verify
bundle doctor ssl --host=gems.example.com

Confirmed by nginx.org

Did this fix it?

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.

Which stack is behind this page?

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.