Blog · Developers
How do I clean the Homebrew cache?
Run `brew cleanup --prune=all`. It removes old versions of what you have installed and every cached download, and Homebrew fetches anything it needs again on the next install.
Homebrew keeps two kinds of leftovers: the downloaded bottles and source archives it installed from, and old versions of formulae you have since upgraded. Neither is needed to run what you have installed, and on a busy machine together they reach several gigabytes.
Where it is
brew --cache
On most Macs that prints ~/Library/Caches/Homebrew. To see how big it is:
du -sh "$(brew --cache)"
See what cleanup would remove, without removing it
brew cleanup -n
The -n is a dry run: it lists what would go and frees nothing. Worth running once before the real
thing, to see where the space is.
Clean it
brew cleanup
That removes outdated versions of installed formulae and cached downloads older than Homebrew’s default age limit. To clear every cached download regardless of age, which is usually what you want when the disk is full:
brew cleanup --prune=all
Two related commands that are not cache, but often free space at the same time:
brew autoremoveuninstalls dependencies that nothing you installed needs any more.brew listis worth reading once in a while — a formula you installed for one job years ago is still there until youbrew uninstallit.
Is it safe?
Yes. Nothing you are using depends on the cache: installed formulae live in Homebrew’s own prefix,
not in the download cache. The only cost is that the next brew install or brew upgrade of
something you cleaned has to download it again.
Why it grows back
Every upgrade downloads new bottles, and Homebrew only tidies up after itself periodically. So the cache creeps back between cleanups; on the Mac this app was built on it was cleaned on 26 August and needed it again by 5 September. That is normal, and a regular clean is the answer rather than a bigger one.
Letting RefreshYourMac do it
RefreshYourMac measures Homebrew’s download cache as Homebrew Downloads, rated Safe to Remove.
Cleaning it runs brew cleanup --prune=all first, so old versions go too, and then clears what is
left of the cache. Nothing is removed without a confirmation, and because it is Safe to Remove it can
also be part of Clean All Safe or a scheduled clean, which keeps it from creeping back.
The other package caches sit beside it — npm, Yarn and pnpm, CocoaPods and Gradle — each measured and cleaned separately. More in what fills up a developer’s Mac.