Developer Files

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

Every package manager keeps a copy of what it downloads, so the next install is faster. That’s useful, but the copies are never cleaned up on their own. After a year or two of projects, package caches on a developer’s Mac often add up to 10, 20 or 30 GB.

These caches are safe to clear: nothing in your projects depends on them, and each tool downloads what it needs again. The only cost is a slower first install afterwards.

See how big they are

This lists the usual cache folders with their sizes, smallest first:

Terminal
du -sh ~/.npm ~/Library/Caches/Yarn ~/Library/pnpm ~/Library/Caches/pip ~/.cache/uv ~/Library/Caches/pypoetry ~/Library/Caches/Homebrew ~/Library/Caches/CocoaPods ~/.gradle/caches ~/go/pkg/mod ~/.bun/install/cache 2>/dev/null | sort -h

Folders you don’t have are skipped. Below, each tool’s own command is the safest way to clear its cache, because it knows what’s still in use.

JavaScript

npm

npm keeps its cache in ~/.npm. Clear it with:

Terminal
npm cache clean --force

The --force is npm’s way of asking you to be sure; it’s safe. If you only want to fix a broken cache rather than empty it, run npm cache verify instead.

Yarn

Terminal
yarn cache clean

On Yarn 2 and later, add --all to clear the shared cache too.

pnpm

pnpm keeps one shared store for all your projects. This removes only the packages no project uses any more:

Terminal
pnpm store prune

Bun

Terminal
bun pm cache rm

Python

pip

Terminal
pip cache purge

To see where it is and how big it is first, run pip cache dir and pip cache info.

uv

Terminal
uv cache clean

uv cache prune is gentler: it only removes entries uv no longer needs.

Poetry

Terminal
poetry cache clear PyPI --all

Homebrew

Homebrew keeps old versions of what you’ve installed and the files it downloaded. This removes both:

Terminal
brew cleanup --prune=all

Run brew cleanup -n first to see what it would remove without removing anything.

Apple platforms

CocoaPods

Terminal
pod cache clean --all

Xcode has much bigger folders of its own. See how to delete Xcode DerivedData, old simulators and device support.

Java and Android

Gradle

Gradle’s cache in ~/.gradle/caches can grow very large. Stop any running Gradle processes first:

Terminal
gradle --stop

Then remove the cache folder:

Terminal
rm -rf ~/.gradle/caches

The next build downloads dependencies again, which can take a while for big Android projects.

Go

Terminal
go clean -modcache

What not to delete

  • node_modules folders inside your projects. They aren’t caches; they’re your project’s installed packages. You can delete them in projects you’ve finished with, and npm install brings them back, but check first that the project still has its package.json and lock file.
  • Virtual environments (.venv, venv) inside Python projects. Like node_modules, they can be rebuilt, but only if you still have the project’s requirements file.
  • ~/.cargo/bin and ~/go/bin. These hold tools you’ve installed, not caches.

Keep them small

  • Run the cleanup commands every few months, or after finishing a big project.
  • brew cleanup runs on its own now and then, but it keeps recent downloads. --prune=all clears them all.
  • If you’ve stopped using a language, remove its tools too, and their caches go with them.
Developer Files results: 7.19 GB found from 7 tools on this Mac
Developer Files

Or let Tinymop check

Developer Files finds the caches of npm, Yarn, pnpm, Bun, pip, uv, Poetry, Homebrew, CocoaPods, Gradle, Maven and Cargo alongside Xcode build files and simulators, and shows each one with its size. Only things your tools rebuild are ticked, and you choose what goes.

Download for Mac
Clean build ✓DerivedData5.01 GB
cleared