Guide

Package manager caches.
One command each.

Every package manager keeps a copy of what it downloaded. Here is where each one keeps it and how to clear it with its own tools.All guides · Updated

What these caches are.

When a package manager downloads something, it keeps a copy so the next install doesn't have to download it again. Most of them never throw those copies away on their own. After a few years of projects, the caches on a developer's Mac can add up to many gigabytes.

They are caches in the plain sense: none of your code lives there. Clearing one costs you the download the next time a project needs a package, and nothing else. Each tool has its own command for it, and that command is the right way in, because it knows which files are in use. Where a tool tells you not to touch its cache by hand, this guide says so.

See them all at once.

This prints the size of each default cache location that exists on your Mac and skips the ones that don't:

du -sh ~/Library/Caches/Homebrew ~/.npm ~/Library/pnpm/store \
  ~/Library/Caches/Yarn ~/.yarn/berry/cache ~/.bun/install/cache \
  ~/Library/Caches/pip ~/.cache/uv ~/.cargo/registry ~/.cargo/git \
  ~/.rustup/toolchains ~/Library/Caches/ms-playwright 2>/dev/null

If you moved a cache with a setting or an environment variable, ask the tool instead. Each section below starts with the command that prints its real path.

Homebrew: brew cleanup.

brew --cache prints the download cache, ~/Library/Caches/Homebrew by default. See what a cleanup would remove first:

brew cleanup -n

Plain brew cleanup removes outdated downloads, downloads older than 120 days, and old versions of the formulae you have installed. Two options go further:

  • -s scrubs the cache, including downloads for the latest versions. Downloads of formulae and casks you have installed still stay.
  • --prune=all removes every cache file, whatever its age.
brew cleanup -s --prune=all

Homebrew also cleans up on its own: after brew install, upgrade and reinstall for the packages involved, and every 30 days for all of them, unless you set HOMEBREW_NO_INSTALL_CLEANUP. Its manual page lists the details.

brew autoremove is different: it uninstalls formulae that were only installed as a dependency of another formula and are no longer needed. It isn't a cache, but it frees space too. Run brew autoremove -n to see the list first.

npm: npm cache clean --force.

npm config get cache prints the cache folder, ~/.npm by default. Downloaded packages live in ~/.npm/_cacache.

The npm documentation is clear that npm will not remove anything from this cache by itself, and that it never needs clearing except to reclaim disk space. The gentle option garbage-collects data npm no longer needs and checks the rest:

npm cache verify

To empty it, npm wants --force, because it would rather you didn't:

npm cache clean --force

That deletes ~/.npm/_cacache and nothing else. The packages npx downloads to run commands live next to it, in ~/.npm/_npx, and can be the bigger of the two. On the Mac this guide was written on, _npx was more than ten times the size of _cacache. Since npm 11.2, npm can list and clear it:

npm cache npx ls
npm cache npx rm --force

Your projects' node_modules folders are not part of the cache. Old ones are usually where more space hides; the node_modules guide covers finding and removing them.

pnpm: pnpm store prune.

pnpm store path prints the store. On macOS it lives in ~/Library/pnpm/store, in a subfolder named after the store layout version, such as v10.

The store is shared: every project's node_modules is linked or cloned from it rather than copied, which is pnpm's way of saving space. So don't delete the store by hand. Prune it:

pnpm store prune

According to the pnpm documentation, this removes packages that no project on your Mac uses any more, such as old versions left behind by updates. It has no effect on your projects; if one needs a removed package later, pnpm downloads it again.

Prune works on the store of the pnpm version you run it with. Different pnpm versions can use different store folders: on the Mac this guide was written on, pnpm store path from pnpm 10 pointed to an empty v10, while the packages a newer pnpm had installed sat in v11. If ls ~/Library/pnpm/store shows more than one folder, measure each with du -sh and run prune with the pnpm version that uses it.

Yarn: yarn cache clean.

Yarn 1 (Classic) keeps one global cache. yarn cache dir prints it; on macOS that is ~/Library/Caches/Yarn. yarn cache clean clears it, and the next yarn install fills it again.

Yarn 2 and later keep a global cache in ~/.yarn/berry/cache by default, and some projects keep their own in .yarn/cache. Here yarn cache clean removes the project's local cache, --mirror removes the global one, and --all removes both. A project that commits .yarn/cache to Git for offline installs needs it there; leave those alone.

Bun: bun pm cache rm.

Bun keeps its cache in ~/.bun/install/cache, or wherever BUN_INSTALL_CACHE_DIR points. bun pm cache prints the path and bun pm cache rm clears it. In Bun 1.3, both refuse to run outside a project (“No package.json was found”), so run them from any project folder.

On macOS, Bun fills node_modules with APFS clones of the cached files. A clone shares its disk blocks with the original, so clearing the cache frees only the packages that no project's node_modules still shares.

pip and uv: clear the Python caches.

pip keeps downloaded and locally built packages in ~/Library/Caches/pip on macOS. Ask it for the path and the size, then clear it:

python3 -m pip cache dir
python3 -m pip cache info
python3 -m pip cache purge

pip cache purge removes everything; pip cache remove <pattern> removes only matching packages.

uv's cache is in ~/.cache/uv on macOS, not in ~/Library/Caches; uv cache dir confirms it. uv has two commands:

uv cache prune
uv cache clean

uv cache prune removes unused entries, such as those left by older uv versions, and is meant to be safe to run now and then. uv cache clean empties the whole cache and waits until no uv process is using it. The uv documentation warns that it is never safe to modify the cache directly, so use these rather than deleting files in it.

Cargo and rustup: crates and toolchains.

Cargo keeps downloaded crates in ~/.cargo/registry (compressed in registry/cache, unpacked in registry/src) and Git dependencies in ~/.cargo/git, as the Cargo book describes.

Since Rust 1.88, Cargo cleans this cache on its own: it removes files downloaded from the network that haven't been used for 3 months, and files from your local system unused for 1 month. It doesn't do this when you build with --offline or --frozen. There is no stable built-in command to clear the cache on demand. cargo-cache is a third-party tool that shows and removes parts of it, installed with cargo install cargo-cache.

cargo clean is per project: it deletes that project's target/ folder, the build output, not the shared cache. Toolchains are separate again, in ~/.rustup/toolchains. List them and uninstall the ones you no longer use:

rustup toolchain list
rustup toolchain uninstall nightly

Playwright browsers.

Playwright downloads its own Chromium, Firefox and WebKit into ~/Library/Caches/ms-playwright, a few hundred megabytes per browser. It tracks which installations still need each browser version and removes versions nobody needs when you install, unless PLAYWRIGHT_SKIP_BROWSER_GC is set. To remove them yourself:

npx playwright uninstall        # this project's Playwright version
npx playwright uninstall --all  # every Playwright installation

The next npx playwright install downloads them again.

All of them in one table.

ToolDefault path on macOSClear it with
Homebrew~/Library/Caches/Homebrewbrew cleanup -s --prune=all
npm~/.npm/_cacachenpm cache clean --force
npx~/.npm/_npxnpm cache npx rm --force
pnpm~/Library/pnpm/storepnpm store prune
Yarn 1~/Library/Caches/Yarnyarn cache clean
Yarn 2+~/.yarn/berry/cacheyarn cache clean --mirror
Bun~/.bun/install/cachebun pm cache rm
pip~/Library/Caches/pippip cache purge
uv~/.cache/uvuv cache prune or uv cache clean
Cargo~/.cargo/registry, ~/.cargo/gitAutomatic since Rust 1.88
rustup~/.rustup/toolchainsrustup toolchain uninstall
Playwright~/Library/Caches/ms-playwrightnpx playwright uninstall --all

Gradle and Maven caches work differently and have a guide of their own.

How Specula handles it.

Specula's list of known locations includes these caches: npm, pnpm, Yarn, Bun, Playwright and Puppeteer browsers, pip, uv and Poetry, the Cargo registry and rustup toolchains, and Homebrew's download cache. Each one shows its size and safety level, and its cleanup command where the tool has one. All of them are marked regenerable: the tool recreates them when it needs them.

In the Clean Up plan, caches their tools recreate are checked by default. Where the tool can clean up after itself, Specula runs the tool: npm cache clean --force for npm, pnpm store prune for pnpm, and, when Homebrew is installed, brew cleanup -s, sized beforehand with a dry run. The other caches are removed as folders. Nothing runs or is deleted without your confirmation.