Clean up Homebrew: old versions, downloads and unused dependencies

What brew cleanup removes, how to preview it, how to clear the download cache completely, and how to remove dependencies nothing needs any more.

Homebrew keeps the installer for every formula and cask it has downloaded, and old versions of formulae after an upgrade. It tidies some of this by itself, but the download cache in particular grows quietly.

See what is there

du -sh "$(brew --cache)"     # downloaded bottles and casks
brew cleanup -n              # dry run: what cleanup would remove, and how much

Clean

brew cleanup                 # old versions, and downloads older than 120 days
brew cleanup --prune=all     # also every cached download, whatever its age
brew autoremove              # formulae installed only as dependencies that nothing needs now

Leave the Cellar alone

Do not delete things under /opt/homebrew or /usr/local by hand. Homebrew tracks what it installed there, and a manual delete leaves it believing the files still exist.

How Siftaway handles this

Siftaway reports the Homebrew download cache with its size and the matching brew cleanup command, and treats /opt/homebrew and /usr/local as never-delete locations. Cleaning the download cache is part of the free tier.