brew cleanup: How to clear Homebrew cache on Mac

You can clear Homebrew cache on a Mac with brew cleanup without risk: the cache holds old downloads of formulae and apps and old versions of the tools you upgraded. Homebrew cleans up now and then by itself, but the cache still grows to gigabytes. Here is how to clean it partly or fully, remove dependencies you no longer need, and what stays.

MacWashing, System Junk: Xcode junk, user caches, installers and logs found, 22.83 GB ready to be cleaned
  1. Open MacWashing and choose System Junk in the sidebar.
  2. Click Start Scan.
  3. Look through what it found and click Clean. Anything debatable stays unchecked.

Free trial · macOS 14 or later

What Homebrew keeps

Homebrew saves every file it downloads, formulae and casks alike, in its download cache. This command shows where it is, by default ~/Library/Caches/Homebrew:

brew --cache
Terminal: brew --cache prints the Homebrew cache folder

Besides downloads, old versions of upgraded formulae stay installed until a cleanup removes them.

Clean up with brew cleanup

A cleanup removes outdated downloads of all formulae and casks, downloads older than 120 days, old versions of installed formulae and stale lock files. To see first what it would remove, run:

brew cleanup -n
Terminal: brew cleanup -n lists what it would remove and how much space it would free

Then run the cleanup itself:

brew cleanup

The current versions of your formulae and the apps installed with --cask stay.

How to clear Homebrew cache completely

This command deletes all cache files, whatever their age. Homebrew downloads again what it needs for the next install or upgrade:

brew cleanup --prune=all

The -s option also scrubs downloads of the latest versions, which a normal cleanup keeps.

Remove dependencies you no longer need

When you uninstall a formula, the formulae it depended on stay. The autoremove command uninstalls formulae that were installed only as a dependency and no longer needed by anything. See the list first:

brew autoremove -n
Terminal: brew autoremove -n lists the dependencies no formula needs anymore

To keep a tool from the list that you use yourself, first add its name to the HOMEBREW_NO_CLEANUP_FORMULAE environment variable: Homebrew never cleans up or autoremoves the formulae listed there. If the list is fine, run:

brew autoremove

Automatic cleanup

  • The install, upgrade and reinstall commands clean up after the formulae they touched, and every 30 days they clean up all formulae.
  • HOMEBREW_CLEANUP_MAX_AGE_DAYS changes the 120-day limit for cached files.
  • HOMEBREW_NO_INSTALL_CLEANUP turns automatic cleanup off. Then run the cleanup yourself: brew cleanup

New to Homebrew? See how to install Homebrew.

With MacWashing, it’s one click

MacWashing, System Junk: Xcode junk, user caches, installers and logs found, 22.83 GB ready to be cleaned

System Junk in MacWashing clears the Homebrew download cache together with the caches of your other apps and tools. Your installed formulae and casks stay.

Free trial · macOS 14 or later

Questions and answers

Will MacWashing delete my own files when it cleans?

No. It removes only what it can match to a known app or a known kind of junk, in places apps leave files; macOS and Apple’s files are never touched. Anything debatable is marked and stays unchecked until you decide.

What about apps that are open?

If an open app holds files being cleaned, MacWashing waits for it to quit or quits it at your request, and opens it again afterwards.

Is it free?

Yes, within the free trial: System Junk and the Uninstaller free up to 25 GB in total, with no account or card needed.

Does brew cleanup uninstall anything?

It removes old versions of formulae you upgraded, never the current ones. Apps installed with --cask stay. To remove unneeded dependencies, use: brew autoremove

Is it safe to delete ~/Library/Caches/Homebrew?

Yes. It holds downloads that Homebrew fetches again when needed. The same from Terminal: brew cleanup --prune=all

How often should I run brew cleanup?

Homebrew cleans up after upgrades and fully every 30 days by itself. Run it by hand when you need space, or after big upgrades.