Skip to content

How to Clear the npm Cache (npm cache clean --force)

2 min read

Applies to: npm 11 with Node.js 24 LTS (tested with npm 11.17 and Node.js 24.19 on AlmaLinux 9)

npm keeps a copy of every package it downloads in a cache, so the next install is faster. Clearing it is rarely needed, but it helps when installs fail with strange integrity or “corrupted” errors, or when you want the disk space back.

Where the cache is

npm config get cache       # usually ~/.npm on Linux and macOS
du -sh ~/.npm/_cacache

On Windows it is %LocalAppData%\npm-cache.

Clear it

npm cache clean --force

Without --force, npm refuses. Our test printed:

npm error As of npm@5, the npm cache self-heals from corruption issues by treating integrity mismatches as cache misses.
npm error As a result, data extracted from the cache is guaranteed to be valid.
npm error If you want to make sure everything is consistent, use `npm cache verify` instead.

With --force it warns npm warn using --force Recommended protections disabled. and removes the _cacache folder.

Check it instead of deleting it

npm cache verify

This checks the cache, removes unneeded data and reports the result, for example Cache verified and compressed (~/.npm/_cacache). Try this first.

When an install keeps failing

  1. npm cache verify
  2. Delete the project’s installed packages and reinstall: rm -rf node_modules, then npm ci (with a package-lock.json) or npm install.
  3. Only if that doesn’t help: npm cache clean --force and install again.
  4. Check the Node.js version the project needs (node -v).

Other package managers

yarn cache clean
pnpm store prune

Installing Node.js and npm: install Node.js and npm on Linux.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket