What is the npm cache (~/.npm) on Mac? Is it safe to delete?
Yes, the npm cache is safe to delete. It is a local copy of packages npm has already downloaded, and npm fetches anything missing from the registry the next time you install.
Where it is
~/.npm/_cacacheWhat it is
Every time npm installs a package, it saves the downloaded archive and its metadata in ~/.npm/_cacache. Later installs of the same version, in any project, can then come from disk instead of the network.
The cache only ever grows. npm does not remove old versions, so every release of every package you have installed stays there.
The ~/.npm folder also holds logs and the packages that npx has run. They are small by comparison, and they are also safe to remove.
How big it gets
Often a few GB after a year or two of regular JavaScript work.
How to clear it by hand
- Open Terminal.
- Run the command below. It deletes everything in npm's cache folder. npm asks for --force because it considers the cache self-healing and clearing it rarely necessary.
- If you only want npm to check the cache and drop unneeded data, run npm cache verify instead.
npm cache clean --forceWhat happens afterwards
Your projects and their node_modules folders keep working. The next installs download packages from the registry again, so they take longer and need a network connection.
How Diskzy handles it
Diskzy lists the npm cache in the Clean up tab and ticks it, along with the other package-manager caches it treats the same way.
Related guides
See where your Mac's space went
Diskzy maps your disk, explains System Data and clears what's safe. Free for 72 hours, then $9 once for 2 Macs.
Try Diskzy for free