Buy Pro

Guides Package caches

How to clear npm, Homebrew and other developer caches on a Mac

Package managers keep every download, and old projects keep their node_modules. Here's where each one keeps its files, and the command to clear it.

Updated 20 November 2026

Why it adds up

Each package manager keeps a copy of everything it has ever downloaded, so the next install is faster. Every project then keeps its own node_modules, virtual environment or build folder on top. A few years of side projects can add up to 20 GB or more.

All of it can be downloaded or rebuilt again. The cost is time: the next install or build takes longer.

See how much each one uses

Open Terminal and run:

du -sh ~/.npm ~/Library/Caches/Yarn ~/Library/pnpm/store ~/.bun/install/cache ~/Library/Caches/Homebrew ~/Library/Caches/pip ~/.cargo/registry ~/.gradle/caches ~/Library/Caches/CocoaPods ~/Library/Caches/ms-playwright ~/go/pkg/mod 2>/dev/null | sort -h

Folders you don’t have are skipped.

Clear each one with its own command

Use the tool’s own command where it has one. It knows which files are still in use.

Tool Command
npm npm cache clean --force
Yarn yarn cache clean
pnpm pnpm store prune
Bun bun pm cache rm
Homebrew brew cleanup
pip pip cache purge
CocoaPods pod cache clean --all
Go go clean -modcache

Cargo, Gradle and Playwright have no built-in command for this:

  • Cargo: move ~/.cargo/registry to the Trash. Cargo downloads what it needs on the next build.
  • Gradle: stop Gradle first with gradle --stop, then move ~/.gradle/caches to the Trash.
  • Playwright: move ~/Library/Caches/ms-playwright to the Trash, and reinstall the browsers you need with npx playwright install.

pnpm store prune only removes packages no project uses any more. That’s usually what you want.

Old projects’ build folders

The other big one is the folders inside your projects that tools rebuild:

Folder Made by Rebuild with
node_modules npm, Yarn, pnpm npm install
.next, .turbo Next.js, Turborepo the next build
target Rust cargo build
.build Swift swift build
.venv, venv Python recreate it and reinstall

To list every node_modules folder in your home folder with its size, run:

find ~ \( -path ~/Library -o -path ~/.Trash \) -prune -o -type d -name node_modules -prune -exec du -sh {} + 2>/dev/null | sort -h

It can take a minute on a full disk. Start with projects you haven’t opened in months. Leave the ones you work on, or you’ll be reinstalling every day.

A node_modules folder that isn’t inside a project, such as ~/.npm-global/lib/node_modules, holds the tools you installed with npm install -g. Leave that one.

Python virtual environments are the exception. Some hold packages installed by hand that aren’t listed in requirements.txt. Check before you remove one.

Xcode, Docker and AI models

These have their own guides: Xcode, Docker and local AI models.