Is it safe to delete ~/.npm, npm’s cache?
- Yes.
~/.npmonly holds copies of packages npm has already downloaded, plus logs and tools fetched bynpx. Your projects, theirnode_modulesand your global packages aren’t in it. - What it costs you: the next install of each package downloads it again, so that install needs the network and takes longer.
- Does it come back? Yes. npm adds to it with every install and never removes anything on its own.
- SiftMac’s verdict: Rebuilds
1. What’s inside ~/.npm
npm keeps a copy of every package tarball and registry answer it fetches, so installing the same version again can skip the download. Entries are stored by a hash of their contents and checked against that hash on the way in and on the way out. A damaged entry is fetched again instead of breaking an install, which is why npm calls its cache self-healing.
_cacache: the cache proper, with downloaded tarballs and package metadata. This is the big part._npx: packages thatnpx(ornpm exec) downloaded to run a command no project of yours has installed, like a project generator you ran once._logs: debug logs from recent npm runs.
npm’s documentation is plain about growth: npm will not remove data by itself, and the cache grows as new packages are installed. Every version of every dependency from every project you’ve installed is in there until something clears it.
2. Where npm keeps it
~/.npm
That’s the default on a Mac, set by npm’s cache setting. If you or a tool changed it, npm will tell you where it is:
npm config get cache
The folder is hidden in Finder. Press ⇧⌘G and paste the path, or press ⇧⌘. in your home folder to show hidden items.
3. How big it gets
There’s no size limit, so the number reflects how many projects you’ve installed and how often their dependencies changed since the folder was last cleared. To see the total and which part holds it:
du -sh ~/.npm
du -sh ~/.npm/_cacache ~/.npm/_npx ~/.npm/_logs
4. Clearing it the npm way
- Let any
npm installthat’s running finish. - For a trim, run
npm cache verify. It checks the cache, garbage-collects data nothing points to any more, and reports what it removed. Sometimes that’s enough. - To empty it, run
npm cache clean --force. npm asks for--forceon purpose: its docs say clearing should never be needed for any reason other than getting disk space back.
npm cache verify
npm cache clean --force
The _npx folder can go as well; npx downloads a tool again the next time you run it. With npm not running:
rm -rf ~/.npm/_npx/*
Leave ~/.npmrc alone. It’s a separate file in your home folder with your npm settings and any registry tokens you’ve logged in with.
5. What happens after you clear it
- Your projects keep working. Code runs from each project’s own
node_modules, never from the cache. - The next
npm installornpm cidownloads each package from the registry again. The first install after clearing is the slow one; the cache fills as it goes. - Versions don’t change:
package-lock.jsondecides what gets installed, not the cache. - An install with
--offlinefails for anything not cached yet, so clear it while you’re online.
6. Other npm folders worth knowing
Global packages from npm install -g aren’t in ~/.npm; they live under npm’s prefix, which npm prefix -g prints. Each project’s packages are in its own [node_modules](/safe-to-delete/node-modules), the other place to look in projects you’ve finished with. Other package managers keep separate caches: Yarn, pnpm and Bun.
Questions
Why does npm cache clean ask for --force?
Clearing is made deliberate because it doesn’t fix anything: npm verifies every cached file when it reads it and refetches damaged ones. The docs name disk space as the only good reason, so add --force when that’s what you want.
Will clearing the npm cache break my projects?
No. Nothing you run reads from ~/.npm. Only installs use it, and an install downloads whatever is missing.
Does npm ever clean its cache automatically?
No, the folder only grows. npm cache verify comes closest to a trim: it drops data the cache index no longer points to and keeps the rest.
What is the _npx folder?
Packages npx fetched to run one-off commands. They’re safe to delete; the next npx run of that tool downloads it again.
How SiftMac handles it. SiftMac doesn’t empty ~/.npm itself. Its space map shows how big the folder is and labels it as npm’s cache: packages npm downloaded before, which come back when a project needs them. npm cache clean --force does the clearing. Under Developer files, SiftMac lists node_modules in projects you haven’t changed for months.
Download SiftMac · scanning is free, and so is your first 2 GB of cleaning · See how it works