This error occurs when your system clock is set to a date before an SSL certificate's validity period begins, causing npm to reject the registry connection. Fixing your system time is the primary solution.
Fixes npm ERR! code CERT_NOT_YET_VALID npm ERR! errno CERT_NOT_YET_VALID npm ERR! Certificate is not yet valid
# Check current system time
date
# Install NTP if not present (Ubuntu/Debian)
sudo apt-get install ntp
# Restart NTP service
sudo service ntp restart
# For systems using systemd-timesyncd
sudo timedatectl status
sudo timedatectl set-ntp true# Check current system timedate# Install NTP if not present (Ubuntu/Debian)sudo apt-get install ntp# Restart NTP servicesudo service ntp restart# For systems using systemd-timesyncdsudo timedatectl statussudo timedatectl set-ntp truenpm ERR! code CERT_NOT_YET_VALIDnpm ERR! errno CERT_NOT_YET_VALIDnpm ERR! Certificate is not yet valid
The CERT_NOT_YET_VALID error is an SSL certificate validation failure that happens when Node.js and npm verify the certificate from the npm registry (registry.npmjs.org). SSL certificates have a validity period with a start date and end date. When your system's date and time are set to a point before the certificate's start date, the certificate appears invalid to your machine, even though it's actually valid. This commonly occurs after rebooting systems without internet connectivity, across timezone changes without clock adjustment, or on devices like Raspberry Pi without battery-backed clocks.
Click the time/date display in the bottom-right corner of your taskbar. In the 'Date & time' settings window, ensure 'Set time automatically' toggle is enabled. This will sync your system to an internet time server.
For fastest results, restart your computer after enabling automatic time sync.
Ensure NTP (Network Time Protocol) is installed and running to keep your clock synchronized:
# Check current system time
date
# Install NTP if not present (Ubuntu/Debian)
sudo apt-get install ntp
# Restart NTP service
sudo service ntp restart
# For systems using systemd-timesyncd
sudo timedatectl status
sudo timedatectl set-ntp trueAfter updating, verify the time is correct with date command.
Older versions of Node.js and npm may have outdated or incomplete CA certificates. Upgrading ensures you have current certificate validation:
node --version
npm --version
npm install -g npm@latestFor Node.js, use nvm (Node Version Manager):
nvm install node
nvm use nodeOnce your clock is synchronized, retry your npm operation:
npm cache clean --force
npm install lodash --save-dev
npm installIf the error persists after confirming your system time is correct, the root cause may be elsewhere.
If you absolutely must proceed while troubleshooting the system clock, you can temporarily disable strict SSL validation. Warning: This reduces security:
export NODE_TLS_REJECT_UNAUTHORIZED=0
npm install
# Persistent (not recommended)
npm config set strict-ssl false
# Revert when done
npm config set strict-ssl true
unset NODE_TLS_REJECT_UNAUTHORIZEDAlways re-enable SSL verification and fix the underlying clock issue.
For corporate environments behind SSL inspection proxies: configure a custom CA certificate bundle using npm config set cafile '/path/to/ca-bundle.crt' or set NODE_EXTRA_CA_CERTS=/path/to/ca-bundle.crt. On containerized systems (Docker, Kubernetes), ensure time synchronization is properly inherited from the host system. Raspberry Pi users without hardware clock modules should run ntpd as a service to maintain time synchronization across reboots.