How to fix npm ERR! certificate has expired in npm
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- Check your system date and time
- Check which certificate is expired
- Update system CA certificates
- Update Node.js
# Check current datedate# Sync time (Linux)sudo ntpdate pool.ntp.org# orsudo timedatectl set-ntp true# Windowsw32tm /resyncnpm 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
- System date/time is incorrect
- Corporate proxy certificate expired
- Outdated CA certificate bundle on system
- Intermediate certificate in chain expired
- Old Node.js version with expired bundled CAs
- Cached expired certificate
- Antivirus certificate expired
How to fix "npm ERR! certificate has expired"
Incorrect system time can cause certificate validation failures:
# Check current date
date
# Sync time (Linux)
sudo ntpdate pool.ntp.org
# or
sudo timedatectl set-ntp true
# Windows
w32tm /resyncIdentify the expired certificate:
openssl s_client -connect registry.npmjs.org:443 2>/dev/null | openssl x509 -noout -datesThis shows notBefore and notAfter dates.
Refresh your system's certificate bundle:
# 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 UpdateOlder Node.js versions may have outdated CA bundles:
# Check version
node --version
# Update via nvm
nvm install --lts
nvm use --lts
# Or update npm directly
npm install -g npm@latestRemove potentially cached bad certificates:
npm cache clean --force
rm -rf ~/.npm/_cacacheIf behind corporate proxy:
1. Ask IT for updated corporate CA certificate
2. Check if proxy certificate needs renewal
3. Update the cafile configuration:
npm config set cafile /path/to/new-corporate-ca.crtAdvanced 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
- ๐npm Official Documentation
- ๐
- ๐ฌStack Overflow: npm+ssl certificate(Stack Overflow)