How to clean up Homebrew cache on Mac and reclaim disk space
Looking for some tips on brew cleanup? I love Homebrew, and I think it really is one of the fastest ways to manage software on your macOS, but don’t forget that every brew install and brew upgrade leaves cached tarballs and old versions behind in ~/Library/Caches/Homebrew.
In just a couple of months, that can build up to around 5–10 GB of dead weight sitting on your machine. The good news is, a simple brew cleanup command is usually the fix. It removes outdated versions and cached downloads without touching anything you actively use.
I’ll show you everything from basic commands to some more aggressive --prune=all cleanup. What to expect when Homebrew auto-cleans on its own, how to set up an update-and-cleanup one-liner, and what to check when cleanup doesn't seem to do anything.
The quick brew cleanup command (and what it actually removes)
The standard Homebrew cleanup command is: brew cleanup
This is going to remove old versions of formulae, any cached downloads like .bottle.tar.gz files, and stale download files that Homebrew no longer needs.
It’s not going to remove the formulae you’re currently using, your taps, or your Homebrew configuration.
If you’re nervous, you can preview what would be removed first; use dry-run mode:
-
brew cleanup -n
If you don’t see any output, that doesn't mean it failed; it usually means there’s nothing to clean.
How much space you get back is, of course, going to totally depend on your install history. I know friends who’ve only reclaimed a few hundred megabytes, while others free up several gigabytes. Phil Nash documented a cleanup that reclaimed about 6.9GB, which is a useful real-world benchmark, but heavy dev machines can vary a lot.
Where’s the Homebrew cache location?
Homebrew cache on Intel Macs and older machines can be found here:
-
~/Library/Caches/Homebrew
But you can also use:
-
brew --cache
To ask Homebrew for the exact cache location on your Mac, instead of relying on the default. Then, if you want to see how much space the cache is using, you can then run:
-
du -sh $(brew --cache)
This is going to check the size of the cache folder only, so that’s different from your installed Homebrew packages. On Apple Silicon Macs, installed formulae usually live under:
-
/opt/homebrew
On Intel Macs, they usually live under:
-
/usr/local
If you discover that your ~/Library/Caches/Homebrew is large, you’re probably looking at downloaded bottles and cached files. If /opt/homebrew or /usr/local is large, that’s your actual Homebrew installation and installed formulae.
Clear Homebrew cache: Aggressive cleanup
If you want more, you’ve also got --prune command
-
brew cleanup --prune=all
It removes all cached downloads, including downloads for versions you currently have installed. It’s way more aggressive than the standard brew cleanup. You can also prune by age. For example, this removes cache files older than seven days:
-
brew cleanup --prune=7
Another option is:
-
brew cleanup -s
Which will include downloads for the latest installed versions in the cleanup.
I do think it’s probably worth saying that yes, you will initially reclaim more disk space, but if Homebrew needs to re-download bottles later, then the build-up happens again. Also, this kind of aggressive cleanup is probably only best used when you’re preparing to hand over a machine, migrating to a new Mac, or dealing with a low-disk emergency, not your everyday kind of cleanup job.
Auto-cleanup and how to disable it
Homebrew is now running cleanup automatically after brew install and brew upgrade, so honestly, you shouldn’t always need to run brew cleanup manually. If you run it and see little or no output, Homebrew probably already cleared the old files for you.
You can always check your current Homebrew setup with:
-
brew config
If you want to disable automatic cleanup, add this to your shell config:
-
export HOMEBREW_NO_INSTALL_CLEANUP=1
For most of us, that means adding it to: ~/.zshrc
Disabling the auto-cleanup on low-bandwidth setups, where re-downloading bottles is painful, or in CI environments where older versions are still needed, kind of makes sense, but otherwise, it’s usually better to leave the automatic cleanup alone and treat manual brew cleanup as an occasional maintenance command.
Brew cleanup all and regular cleanup
Someone shared this with me recently, so returning the Homebrew maintenance routine favor, because this lets you turn the full flow into one shortcut:
-
alias bu="brew update && brew upgrade && brew cleanup && brew autoremove && brew doctor"
This means that when you type: bu, Homebrew will run the whole routine in order:
-
brew update refreshes Homebrew and its formula information.
-
brew upgrade will update your installed formulae to the latest versions.
-
brew cleanup removes old versions and cached downloads Homebrew no longer needs.
-
brew autoremove removes unused dependencies that were installed automatically but are no longer required.
-
brew doctor checks your Homebrew setup and flags anything that might need attention.
To save the shortcut, add the alias to your shell config:
-
nano ~/.zshrc
Paste the alias, save the file, then reload your shell config:
-
source ~/.zshrc
Beyond Homebrew
Homebrew can harbor a lot of cache, but it’s probably not the only offender on your Mac; I’d also think about clearing:
-
~/.npm
-
~/Library/Developer/Xcode/DerivedData
-
~/.gradle/caches
-
~/Library/Caches/pip
-
Docker images
Anyone who’s tried doing this manually will know this can take absolutely ages; I’ve been using the public beta CleanMyMac CLI from MacPaw to do all of this for me in a single command.
Install it with: brew install --cask cleanmymac-cli
Then run:
-
cleanmymac clean dev
This sweeps so much, from Homebrew, npm, Yarn, pnpm, pip, Cargo, Docker, Xcode, VS Code, and JetBrains caches.
I also then run:
-
cleanmymac analyze
And I get an interactive disk explorer to see what's there before deleting anything.
Troubleshooting brew --cache not working
I’ve found time and time again the reason it seems to not be working is because Homebrew's auto-cleanup already ran it, and there’s literally nothing to clean. But you can double-check with:
-
brew cleanup -n
If you come across or suspect any kind of permission errors around /opt/homebrew or /usr/local, you can fix ownership of your Homebrew prefix with:
-
sudo chown -R $(whoami) $(brew --prefix)
The sudo command is only used to repair permissions, not to run Homebrew itself, so don’t start running commands with Sudo.
I’d also check here for HOMEBREW_NO_CLEANUP_FORMULAE. If specific formulae are excluded, Homebrew may be keeping their cached files intentionally.
- brew config
Well, that covers everything on brew cleanup.