Guide

Clear the npm cache on a Mac (and pnpm, Yarn, Bun)

Where each JavaScript package manager keeps its cache on macOS, the command that clears it, and when that helps.

By Rachid Almaach · November 2026

Every package manager keeps a copy of every package it ever downloaded, so the next install is a copy instead of a download. npm, pnpm, Yarn and Bun each have their own cache, in their own place, and none of them empties itself. After a year of JavaScript work the four together are often several GB, and if you switched package managers along the way, the old one's cache is still there.

Clearing a cache is not the fix for most install problems; see the FAQ. But it is a safe few GB when the disk is full.

npm

npm keeps its cache in ~/.npm, with the packages themselves under ~/.npm/_cacache and, since npm 7, the packages npx ran under ~/.npm/_npx. To see where it is and how big:

npm config get cache
du -sh ~/.npm ~/.npm/_cacache ~/.npm/_npx

Since npm 5 the cache checks itself against the package's hash on every read, so a corrupt cache is unlikely and npm asks you to say you mean it:

npm cache clean --force

If you only suspect something is off, verify first. It checks every entry, removes what doesn't belong and reports what it kept:

npm cache verify

pnpm

pnpm works differently: it keeps one content-addressable store and hard links packages from it into every project's node_modules, so a package on disk once is on disk once. The store is in ~/Library/pnpm on macOS unless you moved it:

pnpm store path
du -sh "$(pnpm store path)"

pnpm store prune removes the packages no project on your Mac refers to any more, and leaves everything that is still linked. It is the command to run after deleting old projects or their node_modules:

pnpm store prune

Don't rm -rf the store while projects still link into it: the files in their node_modules share their contents with the store, and pnpm's view of what is installed goes with it. Run pnpm install in each project afterwards if you did.

Yarn

Yarn 1 (classic) keeps a global cache in ~/Library/Caches/Yarn. Yarn 2 and later keep a per-project cache in .yarn/cache and, with the global mirror enabled, a copy in ~/.yarn/berry/cache:

yarn cache dir
yarn cache clean

On Yarn 2 and later yarn cache clean empties the current project's cache; add --mirror to empty the global one. If a project commits .yarn/cache (zero installs), clearing it there means the next yarn install downloads everything again, which is the point of not committing it. Check yarn cache clean --help on your version.

Bun

Bun's cache is in ~/.bun/install/cache:

bun pm cache
bun pm cache rm

What is safe to delete

All four caches. They are copies of packages the registry still has, and the lock file in each project (package-lock.json, pnpm-lock.yaml, yarn.lock, bun.lock) pins exactly which versions come back. The price is one slower install per project and the network for it.

Two things to leave alone. First, the config files next to the caches: ~/.npmrc, ~/.yarnrc.yml and the like hold registry URLs and auth tokens. Clear the cache folders, not the dot files. Second, anything an install is using right now. npm install and pnpm install write to the cache while they run; clearing it under them gives errors that look like network problems.

The caches are also not where the big numbers are. One node_modules is often bigger than the whole npm cache, and a developer Mac has dozens. See find and delete node_modules across all your projects for that.

Or let Sluice do it

Sluice, a menu bar disk cleaner for developer Macs, has a package caches category that covers npm, Yarn, Bun and the caches of other tools on the same Mac (pip, uv, Poetry, CocoaPods, Homebrew, SwiftPM, Maven, Composer, NuGet, Deno, old Playwright browsers). It shows each one with its size and clears the ones you pick when you ask; package caches are not part of its automatic nightly run, because they are cheap to keep and only worth clearing when you need the room. pnpm's store is not in the list; pnpm store prune is the right tool for that. Sluice is free to download and clean with; Pro cleans every night and whenever space runs low.

macOS 14 Sonoma or later · Apple silicon and Intel · or brew install --cask qraft/tap/sluice

FAQ

Will clearing the npm cache fix my install error?

Rarely, since npm 5. The cache verifies every package against its hash, so a corrupt download is thrown away by itself. For ERESOLVE, peer dependency and version errors, look at the lock file and the versions, not the cache. For network errors, try again or check the registry URL in .npmrc. Clear the cache when you want the disk space, or as a last step once the rest is ruled out.

Where is the npm cache on macOS?

~/.npm, with the packages in ~/.npm/_cacache and npx packages in ~/.npm/_npx. npm config get cache prints the path if it was changed. pnpm: pnpm store path. Yarn: yarn cache dir. Bun: ~/.bun/install/cache.

Do I lose anything by clearing it?

Only time. The next install of each project downloads what it needs, guided by its lock file, and ends up with the same node_modules. Nothing in the caches is unique to your Mac. Config files and auth tokens live elsewhere and are not touched by npm cache clean, pnpm store prune, yarn cache clean or bun pm cache rm.