Clear the Homebrew cache on a Mac: why brew cleanup frees so little

Where Homebrew keeps downloads and old versions on a Mac, why plain brew cleanup often frees almost nothing, and the commands that really clear the cache.

Short answer

Homebrew keeps downloads in ~/Library/Caches/Homebrew (brew --cache prints it) and old versions of formulae in its Cellar, /opt/homebrew/Cellar on Apple silicon. Plain brew cleanup often frees almost nothing, because Homebrew already cleans up after itself and keeps recent downloads and the installers of what you have installed. brew cleanup --prune=all clears the whole cache. Run it with -n first to see what goes.

Why brew cleanup frees so little

I ran three dry runs on my Mac (Homebrew 7.0.11, 130 formulae, a 528 MB cache). -n lists what would go and deletes nothing:

Terminal
$ brew cleanup -n               # nothing to remove
$ brew cleanup -s -n            # would free about 12.7 MB
$ brew cleanup --prune=all -n   # would free about 508 MB

The default found nothing at all. Three rules explain it:

  • Homebrew already cleans up. After every brew install, upgrade and reinstall it runs cleanup for those packages, and every 30 days for all of them. Setting HOMEBREW_NO_INSTALL_CLEANUP turns that off, which is the usual reason a cache grows large.
  • Recent downloads stay. The default removes downloads older than 120 days. HOMEBREW_CLEANUP_MAX_AGE_DAYS changes the number.
  • Installers for what you have installed stay, even with -s (scrub). Only --prune=all removes them.

On my Mac, 470 MB of the 508 MB was a single file: the DMG of OrbStack, an app I installed with brew install --cask. Homebrew kept the installer because that version is still installed. Cask installers are often the largest thing in the cache.

See what's in the cache

These only read:

Terminal
$ brew --cache
$ du -sh "$(brew --cache)"
$ du -sh "$(brew --cache)"/* "$(brew --cache)"/Cask/* 2>/dev/null | sort -h | tail

You'll see downloads/ (bottles and installers), Cask/ (app installers), api/ (Homebrew's package index, about 30 MB) and bootsnap/ (a Ruby speed-up cache). The index and bootsnap come back on the next brew command, so there's no point removing them by hand.

Clear it

Terminal
# see the list and the total first
$ brew cleanup --prune=all -n

# then remove
$ brew cleanup --prune=all

--prune=all removes every cached download, whatever its age, plus old logs. It doesn't touch installed formulae or apps. If you reinstall one of them, Homebrew downloads it again.

The help text for brew cleanup also offers rm -rf "$(brew --cache)" to delete everything. It frees about the same space and skips Homebrew's own bookkeeping, so prefer --prune=all.

Safe

An installed formula or app never needs its download to run. The cost of clearing the cache is a fresh download if you reinstall the same version, nothing else.

Old versions in the Cellar

Every formula you install lives in the Cellar, one folder per version. brew cleanup removes old versions, with two exceptions:

  • Pinned formulae (brew list --pinned) keep every version.
  • Outdated formulae. If a newer version exists and you haven't installed it, cleanup skips the formula with Warning: Skipping sqlite: most recent version 3.54.1 not installed. My Cellar still had two versions each of sqlite, sdl3 and sdl2-compat for this reason.

So the order matters. Upgrade first, then clean:

Terminal
$ brew upgrade
$ brew cleanup

To find formulae with more than one version installed:

Terminal
$ cd "$(brew --prefix)/Cellar" && for f in *; do n=$(ls "$f" | wc -l); [ "$n" -gt 1 ] && echo "$f $n"; done

Dependencies you no longer need

When you uninstall a formula, the libraries it pulled in stay. brew autoremove uninstalls formulae that were only installed as a dependency and that nothing needs anymore:

Terminal
$ brew autoremove -n   # list them
$ brew autoremove      # uninstall them

Unlike the cache, this uninstalls software. Look at the list before you run it without -n. It found nothing on my Mac, but it often does after a few big uninstalls.

Check first

brew updates its package index before many commands, which can take a while. Set HOMEBREW_NO_AUTO_UPDATE=1 for the session if you only want to look.

Shedi shows what brew cleanup would free before it runsThe size comes from Homebrew's own dry run, so the number on the row is the number you get. Cleaning runs Homebrew's cleanup, not a folder delete.
Get Shedi

A sensible routine

Terminal
$ brew upgrade
$ brew cleanup
$ brew autoremove -n
$ brew cleanup --prune=all -n   # when you want the whole cache back

Homebrew is rarely the biggest cache on a developer's Mac. On mine, ~/.npm/_npx alone was 3.9 GB, more than seven times the Homebrew cache. To see every cache side by side, run diskreceipt, a free Terminal tool, or read the developer cache reference.

Sources

Questions

Where is the Homebrew cache on a Mac?

In ~/Library/Caches/Homebrew. Run brew --cache to print it. The downloads folder inside holds the bottles and cask installers Homebrew fetched, and Cask holds app installers such as DMGs.

Is it safe to delete the Homebrew cache?

Yes. Installed formulae and apps don't need their downloads to run. Homebrew downloads them again only if you reinstall the same version. Use brew cleanup --prune=all rather than deleting the folder in Finder.

Why does brew cleanup free so little space?

Homebrew already runs cleanup on its own after every install, upgrade and reinstall, and for all packages every 30 days. By default it also keeps downloads younger than 120 days and the downloads of versions you have installed, so a manual brew cleanup often has nothing left to do.

How do I remove everything from the Homebrew cache?

Run brew cleanup --prune=all. It removes every cached download regardless of age, including installers for versions you have installed. Add -n first to see the list and the total without deleting anything.

Does brew cleanup remove old versions of formulae?

Yes, except for pinned formulae and formulae that are out of date. If a newer version exists and you haven't installed it, cleanup skips that formula and keeps its old versions until you run brew upgrade.