ClearDisk
Buy for $10Download ClearDisk
A LITTLE MORE CLARITY

Clean the Homebrew cache on Mac with brew cleanup

Homebrew keeps downloads and old versions around by design. brew cleanup removes them, and its dry run shows the size before anything changes.

1. Find the cache and measure it

Run brew --cache in Terminal. Homebrew’s FAQ says it prints the download cache location, usually ~/Library/Caches/Homebrew. Measure it with du -sh "$(brew --cache)". Both commands only read. Because the folder sits under ~/Library/Caches, macOS counts it inside System Data, which is why a developer Mac can show a large System Data figure with nothing obvious in Documents.

Old versions of installed formulae live separately, inside Homebrew’s Cellar, and are the second thing cleanup removes. A disk scanner shows both locations next to npm, pip and Xcode directories, which helps when the cache is not the largest developer folder on the disk.

brew --cache
du -sh "$(brew --cache)"

2. Preview what cleanup would remove

Run brew cleanup -n first. The manpage describes -n as showing what would be removed without removing anything, and the output ends with the total it would free. Cleanup targets stale lock files, outdated downloads for formulae and casks, and old versions of installed formulae. By default it only removes downloads older than 120 days; --prune=all removes all cache files regardless of age, and -s or --scrub also clears downloads for current versions, except those of installed formulae and casks.

Read the dry run for anything you deliberately keep, such as an older version you pinned for a project. If it appears in the list, resolve that before running the real command rather than restoring it afterwards.

brew cleanup -n

3. Run it, then measure again

When the preview looks right, run brew cleanup. This is the modifying step: it deletes the files the dry run listed. Add --prune=all to remove every cached download, or -s to scrub downloads for current versions too. Then repeat du -sh "$(brew --cache)" and compare with the first figure. The difference is the real result; do not assume the dry-run total, because installed-formula downloads are kept.

Homebrew already runs cleanup automatically after brew install, brew upgrade and brew reinstall unless HOMEBREW_NO_INSTALL_CLEANUP is set, and HOMEBREW_CLEANUP_MAX_AGE_DAYS changes the 120-day threshold. If the cache keeps growing on your Mac, check whether that variable is set in your shell profile.

brew cleanup
brew cleanup --prune=all
du -sh "$(brew --cache)"

4. Remove packages you no longer need

Cleanup keeps everything that is installed, so the next saving comes from packages themselves. brew leaves lists formulae that nothing else depends on; brew autoremove -n lists dependencies that were only installed for a formula you have since removed, and brew autoremove uninstalls them. brew list shows every installed formula and cask, and brew uninstall removes one.

Check before uninstalling a runtime such as Python, Node or Ruby: scripts and editors outside Homebrew may rely on it even when no formula does. Casks are ordinary apps; removing one with brew uninstall is the same decision as dragging the app to the Trash.

brew leaves
brew autoremove -n
brew autoremove

5. Keep it from growing back

Leave automatic cleanup enabled and run brew cleanup --prune=all every few months on a small SSD. Do not delete the Cellar or the cache folder by hand in Finder; the FAQ’s supported routes are cleanup and uninstall, and brew uninstall --force is described there as destructive because it removes every installed version at once.

Homebrew is usually one of several developer caches. The related guides cover node_modules folders, Xcode’s Derived Data and Docker’s disk image, which are the other places a developer Mac hides tens of gigabytes. A free local scan lists them together with allocated sizes so you can decide which one is worth the time.

References & further reading

These guides combine the linked official guidance with ClearDisk’s documented behavior. Your files and app settings determine the right next step.

FROM A NUMBER TO AN ANSWER

See what’s using
your space.

Explore your Mac with ClearDisk’s free local scanner.
Review the files. Keep the control.

Download free scannermacOS 15+ · version 1.0Cleanup license: $10 once