Developers · npm

How to clear the npm cache on a Mac

In Terminal, run npm cache clean --force. That empties ~/.npm/_cacache, the download cache npm never trims by itself. It is safe: nothing you have installed lives there, and the next install downloads what it needs again. It does not touch the npx cache in ~/.npm/_npx; on npm 11, npm cache npx rm --force clears that one.

Where the npm cache is on a Mac

npm keeps its cache in ~/.npm, the hidden .npm folder in your home folder, unless you have changed its cache setting. To check:

npm config get cache

Inside it, two folders take the space:

  • _cacache: every package and registry response npm has downloaded, on any project, with any version of Node.
  • _npx: the packages npx installed to run a command once.

To see how big they are:

du -sh ~/.npm/_cacache ~/.npm/_npx 2>/dev/null

npm's own documentation is plain about why it gets big: npm will not remove data by itself, and the cache grows as new packages are installed.

Is it safe to clear?

Yes. npm calls it strictly a cache, not a store to rely on. Your projects' packages are in their own node_modules folders, and global packages are installed elsewhere, so neither is touched. What clearing costs is time: the next npm install downloads everything it needs again, so it is slower and needs a network connection.

It will not fix a broken install, either. npm checks every file going in and out of the cache and fetches again, or reports an error, if anything doesn't match. That is why its documentation says clearing is only worth doing to get disk space back.

Clear it

To tidy first without emptying it, ask npm to check the cache and remove what it no longer needs:

npm cache verify

To empty it:

npm cache clean --force

The --force is required; without it npm refuses and explains why it thinks you don't need to. The command removes the _cacache folder and nothing else in ~/.npm.

The npx cache is separate

npm cache clean --force leaves ~/.npm/_npx alone. On npm 11 there is a command for it (npm cache npx ls lists what is there first):

npm cache npx rm --force

On older npm, which has no such command, move the folder to the Trash instead. The trash command is built into macOS 15 and later:

trash ~/.npm/_npx

The next npx command installs what it needs again. Empty the Trash once you are happy, since nothing is freed until you do.

What clearing the cache doesn't free

Where the app comes in

In the download edition, RefreshYourMac measures this as NPM Cache: ~/.npm/_cacache, the npx installs in ~/.npm/_npx and npm's logs in ~/.npm/_logs. It is rated Safe for auto removal, so it can go in Clean All Safe or a scheduled clean, which keeps it from creeping back. Yarn's and pnpm's caches are their own row beside it. The Mac App Store edition does not have NPM Cache; it has Yarn's cache only. For everything else development tools leave on a Mac, see the Mac cleaner for developers.

What to do next: see these numbers for your own Mac. Download RefreshYourMac free, or get it on the Mac App Store.

What it costs to have an app do this

RefreshYourMacCleanMyMacMacKeeper
Pay once$24.99€119.95 on MacPaw’s store; $89.99 for CleanMyMac X on the Mac App Storesubscription only
Yearly$14.99 a year, first 7 days free$39.99/yr on the Mac App Store; €39.95/yr on MacPaw’s store€71.40 for the first year, 1 Mac. Their page shows it against a €119.40 list price
Monthly$1.99 a month$9.99/mo€10.95/mo
Account neededNoYesYes

Before you pay anything, both versions give you 3 free scans. CleanMyMac and MacKeeper prices read from their own pages and the Mac App Store on 27 October 2026; the full comparison is at RefreshYourMac vs CleanMyMac and MacKeeper.

Frequently asked questions

Where is the npm cache on a Mac?

In ~/.npm, the hidden .npm folder in your home folder, unless you have changed npm’s cache setting; npm config get cache prints where it is. The downloads are in ~/.npm/_cacache, and the packages npx installed are in ~/.npm/_npx.

Is it safe to clear the npm cache?

Yes. npm calls it strictly a cache, and nothing you have installed lives there: projects keep their packages in node_modules. The next npm install downloads what it needs again, so it is slower and needs a network connection.

Does npm cache clean --force clear the npx cache?

No. It removes ~/.npm/_cacache and nothing else. On npm 11, npm cache npx rm --force clears the npx cache; on older npm, move ~/.npm/_npx to the Trash.