How to fix npm ERR! certificate has expired in npm

npmINTERMEDIATEHIGHUpdated Dec 6, 2025ยท 186 views

The "certificate has expired" error occurs when npm encounters an SSL certificate that is past its validity date. This can happen with outdated system CA certificates, expired corporate certificates, or clock synchronization issues.

Quick fix

Fixes npm ERR! certificate has expired

# Check current date
date

# Sync time (Linux)
sudo ntpdate pool.ntp.org
# or
sudo timedatectl set-ntp true

# Windows
w32tm /resync
  1. Check your system date and time
  2. Check which certificate is expired
  3. Update system CA certificates
  4. Update Node.js
npm โ€” error
# Check current date
date
# Sync time (Linux)
sudo ntpdate pool.ntp.org
# or
sudo timedatectl set-ntp true
# Windows
w32tm /resync
npm ERR! certificate has expired

What this error means

This error indicates that an SSL/TLS certificate in the chain has expired. Every SSL certificate has a validity period, typically 1-2 years. When npm connects to the registry, it validates the certificate chain, and if any certificate has passed its expiration date, the connection is rejected. This can occur at multiple levels: the registry's certificate (rare, as npmjs.com keeps theirs updated), an intermediate CA certificate, or a corporate proxy certificate that hasn't been renewed.

Typical symptoms

  • npm install fails with certificate expired error
  • Error started on a specific date
  • All npm operations fail
  • Works on some machines but not others
  • Error appeared after system was offline for a while
  • Browser also shows certificate warnings

Common causes

  1. System date/time is incorrect
  2. Corporate proxy certificate expired
  3. Outdated CA certificate bundle on system
  4. Intermediate certificate in chain expired
  5. Old Node.js version with expired bundled CAs
  6. Cached expired certificate
  7. Antivirus certificate expired

How to fix "npm ERR! certificate has expired"

1Check your system date and time

Incorrect system time can cause certificate validation failures:

bash
# Check current date
date

# Sync time (Linux)
sudo ntpdate pool.ntp.org
# or
sudo timedatectl set-ntp true

# Windows
w32tm /resync
2Check which certificate is expired

Identify the expired certificate:

bash
openssl s_client -connect registry.npmjs.org:443 2>/dev/null | openssl x509 -noout -dates

This shows notBefore and notAfter dates.

3Update system CA certificates

Refresh your system's certificate bundle:

bash
# Ubuntu/Debian
sudo apt update && sudo apt install --reinstall ca-certificates

# CentOS/RHEL
sudo yum reinstall ca-certificates

# macOS
brew install ca-certificates
# or update via Software Update
4Update Node.js

Older Node.js versions may have outdated CA bundles:

bash
# Check version
node --version

# Update via nvm
nvm install --lts
nvm use --lts

# Or update npm directly
npm install -g npm@latest
5Clear npm cache

Remove potentially cached bad certificates:

bash
npm cache clean --force
rm -rf ~/.npm/_cacache
6Contact IT for corporate certificates

If behind corporate proxy:

1. Ask IT for updated corporate CA certificate
2. Check if proxy certificate needs renewal
3. Update the cafile configuration:

bash
npm config set cafile /path/to/new-corporate-ca.crt

Advanced notes

In CI/CD environments, ensure build agents have updated CA certificates and synchronized time (especially for containers). Docker images should be rebuilt periodically to pick up CA updates. For air-gapped environments, manually update CA certificates. If using a time-sensitive HSM or TPM, ensure hardware clock is accurate.

Frequently asked questions

What does "npm ERR! certificate has expired" mean?
This error indicates that an SSL/TLS certificate in the chain has expired. Every SSL certificate has a validity period, typically 1-2 years. When npm connects to the registry, it validates the certificate chain, and if any certificate has passed its expiration date, the connection is rejected.
How do I fix "npm ERR! certificate has expired"?
The "certificate has expired" error occurs when npm encounters an SSL certificate that is past its validity date. This can happen with outdated system CA certificates, expired corporate certificates, or clock synchronization issues.
What causes "npm ERR! certificate has expired"?
System date/time is incorrect Corporate proxy certificate expired Outdated CA certificate bundle on system
Is the "npm ERR! certificate has expired" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading