MacBook App Cleaner
HomeBlog › How to Clear the npm and Yarn Cache on a Mac

How to Clear the npm and Yarn Cache on a Mac

Published July 20, 2026 · 5 min read · By the MacBook App Cleaner team

In short: Node package caches can quietly grow to several gigabytes on a Mac, and a corrupted one is a common cause of failed installs. Here are the exact commands to clear npm, Yarn, and pnpm caches, plus how to do it safely.

If you write JavaScript on a Mac, your package managers keep local caches so repeat installs are faster and can work offline. That is useful, but the cache also grows quietly. On a working machine it is normal to see npm and Yarn caches reach several gigabytes, and a corrupted cache is one of the most common reasons an install suddenly fails. Clearing it is safe, reversible in effect, and often fixes the problem. Here are the exact commands and what each one actually does.

Where the caches live

Everything here sits in your home folder, under your own user account. Nothing is inside /System, and you never need administrator rights or sudo to clean it. The main locations on macOS 14 or 15 (Sonoma and Sequoia) are:

  • npm: ~/.npm (the content-addressable store lives in ~/.npm/_cacache)
  • Yarn Classic (v1): ~/Library/Caches/Yarn
  • Yarn Berry (v2+): a .yarn/cache folder inside each project, plus a global folder under ~/.yarn/berry/cache
  • pnpm: a content-addressable store, usually ~/Library/pnpm/store or ~/.local/share/pnpm/store

To see how big your npm cache is right now, open Terminal and run du -sh ~/.npm. That gives you a real number before you decide to clean anything.

Clear the npm cache

The supported way to empty the npm cache is one command:

npm cache clean --force

Modern npm self-heals its cache, so it treats a manual clean as unusual and requires the --force flag. That is expected. After it finishes, you can confirm the store is healthy with npm cache verify, which also reports the current size and removes any unreferenced or expired entries. In day-to-day use, npm cache verify is the gentler option: it reclaims space without wiping everything, and it is a good first step if you are only trying to tidy up rather than fix a broken install.

If you specifically suspect corruption, the full clean followed by npm cache verify gives you a clean slate. The only cost is that your next install re-downloads packages, so it will be a little slower once.

Clear the Yarn and pnpm caches

For Yarn Classic (v1), the command mirrors npm:

yarn cache clean

Run yarn cache dir first if you want to see exactly which folder it will empty. To wipe a single package instead of everything, pass its name, for example yarn cache clean lodash.

Yarn Berry (v2 and later) works differently. Much of its cache is stored per project in .yarn/cache, and it is designed to be committed or regenerated, so you usually let the project manage it. To clear the global mirror, use yarn cache clean --all from within a Berry project.

For pnpm, run pnpm store prune. Rather than deleting the whole store, prune removes packages that no longer belong to any project on your machine, which is the safest way to recover space without breaking existing installs.

Do it safely and keep it reversible

The commands above are the right tool, because each package manager knows its own cache format and only removes files it created. That is safer than hunting through folders in Finder and dragging things out by hand. If you ever do clean these folders manually, move them to the Trash rather than permanently deleting them. Trash is reversible: if an install misbehaves afterward, you can restore the folder and try again. Anything that skips the Trash and erases files outright takes that safety net away.

One more habit worth keeping: preview before you delete. Check a folder's size and contents first, clear only your own user-level caches, and leave system files alone. Package caches always rebuild themselves on the next install, so there is nothing here you can lose permanently by clearing it the supported way.

If you would rather use an app

Running these commands occasionally is the cleanest approach for developer caches. But if you want a general Mac cleaner that treats your files with the same caution, pick one that previews everything first, defaults to user-level junk only, and sends removals to the Trash so they stay reversible. A trustworthy cleaner also has no reason to phone home. You can verify that yourself with a firewall like Little Snitch and confirm it makes no outbound connections while it scans.

On that bar, a solid free pick is CoreSweep (free forever, with an optional one-time Pro at $49, zero telemetry, and reversible deletes). A strong value runner-up is SkoonMac (free, with a one-time Pro at $19). Either way, the principle is the same: preview first, keep it reversible, and only touch what is genuinely yours to clean.

Frequently asked questions

Is it safe to clear the npm cache?

Yes. The npm cache lives in your home folder under ~/.npm, so you never need sudo or administrator rights to clear it, and the supported command only removes files npm created. Nothing you lose is permanent, because npm rebuilds the cache automatically the next time you install a package. The only cost is that the next install re-downloads packages, so it runs a little slower once.

Why does npm cache clean require the --force flag?

Modern npm self-heals its cache, so it treats a manual clean as unusual and asks you to confirm with --force. That is expected behaviour, not an error. If you are only tidying up rather than fixing a broken install, npm cache verify is the gentler option, since it reclaims space and removes expired entries without wiping everything.

How do I clear the Yarn or pnpm cache instead of npm?

For Yarn Classic (v1), run yarn cache clean, or add a package name like yarn cache clean lodash to remove just one. Yarn Berry (v2+) keeps most of its cache per project in .yarn/cache, so let the project manage it and use yarn cache clean --all for the global mirror. For pnpm, run pnpm store prune, which removes only packages no longer used by any project rather than deleting the whole store.

The easy way to do this safely

If you'd rather not do it by hand, the two cleaners we rate highest run with a preview first and the Trash as a safety net — and neither sends any data off your Mac.

CoreSweep (free to use; Pro a one-time $49) is our top pick. SkoonMac (free; Pro $19 once) is the best-value runner-up. See the full comparison.

← All Mac cleaning guides · Back to the comparison