What is the ~/.npm folder, and is it safe to delete?

The ~/.npm folder is npm's download cache, and it is safe to delete because npm fetches packages again the next time you install them.

Shiva ChandraMaker of Clean House · · 2 min read
Short answer

~/.npm is npm's download cache, mostly in the _cacache folder, with npx packages and logs beside it. It is safe to clear. Run npm cache clean --force and npm fetches packages again on the next install. Your projects, package.json files and node_modules folders are not affected.

Path
~/.npm
What it is
npm's cache of downloaded packages (_cacache), plus npx packages and logs
Typical size
From hundreds of megabytes to several gigabytes, depending on how many projects you install
Made by
npm
Safe to delete?
Safe to clear
Comes back?
Yes, npm re-downloads packages on the next install

What is in this folder?

npm stores every tarball and metadata response it downloads in ~/.npm/_cacache so repeat installs and offline installs are fast. The same folder holds _npx, where one-off npx packages are cached, and _logs.

The npm documentation notes that the cache is self-healing: corrupted entries are refetched automatically, and clearing it should only be necessary to reclaim disk space.

Is it safe to delete?

Yes. Nothing in the cache is unique. Everything in it came from the npm registry and can be fetched again. The only cost is bandwidth and time on the next install.

The one case to avoid is working offline, where the cache may be the only copy of packages you need to install.

How do I clear it by hand?

  1. Stop any running npm install or dev server that is installing packages.
  2. Run the command below. npm requires --force to clear the cache.
  3. Optionally check the state of what remains with npm cache verify.
npm cache clean --force
This clears the cache, not node_modules. Project folders keep working.

How do I stop it growing?

npm does not cap the cache. Running npm cache clean --force every few months keeps it small.

How Clean House handles it

Clean House recognizes ~/.npm/_cacache as the npm cache, made by npm, and marks it as something that downloads again. The Why card says what happens if it goes, and the files go to the Trash before anything is permanent.

Questions

Is it safe to delete ~/.npm?

Yes. It is a cache. npm downloads packages again on the next install.

How do I clear the npm cache?

Run npm cache clean --force. npm requires the force flag.

Does clearing the npm cache delete node_modules?

No. node_modules lives inside each project and is not part of the cache.

Sources

  1. npm Docs: npm cache