Skip to content

Mac cache folders

How to clear the npm cache on a Mac

By · Updated · 3 min read

Short answer

Run npm cache clean --force in Terminal. npm requires --force because its cache is self-healing and clearing is rarely needed. The cache lives in ~/.npm; your projects’ node_modules aren’t touched, and packages download again on the next install. To check the cache instead, run npm cache verify.

Where is the npm cache on a Mac?

  • ~/.npm
  • ~/.npm/_cacache
  • ~/.npm/_npx
  • ~/.npm/_logs

Safe to clear. Cached packages downloaded by npm. Safe to delete and will be re-downloaded when you run npm install.

How do I clear the npm cache with npm?

  1. 1To delete everything in the cache: npm cache clean --force
  2. 2To check the cache instead, without deleting it: npm cache verify. It garbage-collects unneeded data and checks the cache index and data integrity.
  3. 3To find the cache folder: npm config get cache

How do I delete the npm cache by hand?

  1. 1Make sure no npm install is running.
  2. 2In Terminal run: rm -rf ~/.npm/_cacache (and ~/.npm/_npx for npx's cache).
  3. 3Your next npm install downloads packages again.

What happens when you clear it?

npm cache clean removes everything in the cache folder. Installed node_modules in your projects are not affected; packages download again on the next install, and offline installs (--offline) can't fill in missing packages until then. npm's docs say clearing is usually unnecessary, since the cache is self-healing and resistant to data corruption.

Clearing it with Peekaboo

Peekaboo’s developer cleanup (turn on Show developer features in Settings) lists “npm Package Cache” with its size and the note above, alongside every other cache it finds. It won’t offer a folder the app is still running from, and the cleanup goes to the Trash, so ⌥⌘Z puts it back.

  1. 1Open the developer cleanup.⇧⌘B
  2. 2Find npm Package Cache, check its size, and move it to the Trash.

Questions

Why does npm cache clean need --force?

npm's docs say the cache is self-healing and corrupted data is removed automatically, so clearing should only be needed to reclaim disk space. That's why clean now requires --force to run.

Where is the npm cache on a Mac?

npm's docs give the default cache location as ~/.npm on macOS and other POSIX systems. The package data itself is in ~/.npm/_cacache.

Should I run npm cache verify or npm cache clean?

To fix problems, try npm cache verify: it checks integrity and garbage-collects unneeded data without deleting the cache. Use npm cache clean --force only when you want the disk space back.

Sources

Your privacy choices

With your permission, Google Analytics measures visits to this site using cookies. Privacy policy.