How to clear the Homebrew cache on Mac
Homebrew keeps downloaded bottles and cask installers in a cache folder, and keeps old versions of every package it upgrades. The cache is usually small to moderate, from tens of MB to a few GB. The old versions and installed packages under /opt/homebrew are the bigger bill. brew cleanup removes the cache and old versions safely. It cannot remove anything you need to run your current software, so it is the one command to use first. rm -rf on the wrong Homebrew folder removes software, not cache.
Find the cache
brew --cache
On the Mac checked here it printed ~/Library/Caches/Homebrew (spelled out as your home folder). That is the default on Apple silicon and Intel Macs. If you set HOMEBREW_CACHE in your shell profile, the command prints that path instead. Always ask brew where the cache is.
du -sh "$(brew --cache)"
du -sh "$(brew --cellar)"
du -sh /opt/homebrew
Checked here: the cache was 37 MB, the Cellar (installed packages) 2.6 GB, and all of /opt/homebrew 13 GB. The cache was the smallest number. Intel Macs use /usr/local as the prefix and Apple silicon uses /opt/homebrew. brew --prefix prints yours.
What is in the cache folder
Run ls -la "$(brew --cache)". On the Mac checked here it held api (30 MB of formula and cask metadata), bootsnap (7.5 MB of Ruby load cache) and a small linkage.json. A downloads folder appears when bottles and cask installers are waiting there, and that is where the space usually sits. The metadata folders are re-fetched and rebuilt on the next brew update or brew command. Nothing in the folder is yours.
Preview, then clean up
brew cleanup -n
-n (also --dry-run) lists what would be removed and the space it would free, and deletes nothing. The output lines read like Would remove: /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.4.8 (1,584 files, 35.6MB), ending with ==> This operation would free approximately 472.3MB of disk space.
brew cleanup
Removes, permanently:
- Downloads in the cache that are older than 120 days (change with
HOMEBREW_CLEANUP_MAX_AGE_DAYS). - Old versions of installed formulae in the Cellar, once a newer version is installed.
- Outdated cask downloads and stale lock files.
It keeps the current version of everything you have installed. Homebrew already runs a cleanup by itself after brew install, upgrade and reinstall, and a full one about every 30 days. Set HOMEBREW_NO_INSTALL_CLEANUP=1 and it stops, so if old versions are piling up, check your shell profile for that variable. A dry run on a Mac that follows the defaults usually shows only a few hundred MB.
Go further
brew cleanup --prune=all
Removes every cache file regardless of age. Same safety as brew cleanup.
brew cleanup -s
Scrubs the cache, including downloads for the latest versions of things you have not installed. Downloads for installed packages stay.
brew autoremove -n
brew autoremove
Removes formulae that were installed only as dependencies and that nothing needs any more. Run it with -n first. On the Mac checked here it listed one candidate, icu4c@78. Check the list against software you built from source or installed with another tool. Homebrew only knows its own dependency graph, so a program you compiled by hand against a Homebrew library can lose that library.
What is recoverable
Everything in the cache is a re-download. brew install fetches a bottle again, which needs a network. Cask installers re-download the same way. What you cannot get back is an old version after brew cleanup. Homebrew does not keep old bottles forever, and the formula often points only to the latest version. If you rely on an older version of a package, pin it first: brew pin <formula>. Pinned formulae are skipped by upgrade and keep their version.
What not to delete
| Path | What it is |
|---|---|
/opt/homebrew/Cellar | Every installed formula. Deleting a folder here removes that software. |
/opt/homebrew/Caskroom | Records and sometimes the files of installed casks. |
/opt/homebrew/opt, bin | Symlinks to the Cellar. Deleting them breaks commands. |
~/Library/Caches/Homebrew | The cache. Safe. |
This is the point most guides skip. Searches for "Homebrew taking space" lead to /opt/homebrew, which on a developer Mac is 5 to 15 GB, and people sometimes remove folders there that look like leftovers. /opt/homebrew/Library/Homebrew/vendor/portable-ruby is Homebrew's own bundled Ruby, and brew cleanup removes the old versions of it safely. Do not delete the current one by hand.
The manual wipe, rm -rf "$(brew --cache)", is safe only when brew --cache prints a folder inside Library/Caches. Because HOMEBREW_CACHE can point anywhere, an empty or mistyped variable inside a command substitution is the classic way to run rm -rf on the wrong place. Run brew --cache alone and read the answer before wrapping it in rm. Quote it, because paths with spaces split into several arguments.
Reduce the larger part
brew list --formula
brew uses --installed <formula>
brew uninstall <formula>
The Cellar is where the space is. brew uses --installed tells you what depends on a package. Uninstalling a package other formulae need makes Homebrew refuse, unless you add --ignore-dependencies, which breaks them. Do not add it.
Some packages are large for a reason: a full LLVM, Node, Python versions, Android command-line tools and big libraries such as icu4c. Check them with du -sh /opt/homebrew/Cellar/* | sort -h | tail and decide package by package.
Where Spotless fits
The Developer page in Spotless lists the Homebrew download cache with its size and the note "run brew cleanup". It never offers the Cellar or Caskroom for removal and skips the cache while brew is running. It does not run brew autoremove or uninstall formulae for you.
Keep going
- How to clear Xcode DerivedData on Mac: Where Xcode DerivedData lives, how big it gets, the exact commands to clear it safely, and the gotchas with indexes, caches and running builds.
- How to delete iOS Simulators and runtimes in Xcode: Remove old iOS Simulator devices and downloaded runtimes from Xcode, with the commands, the folders involved and what each removal costs.
- node_modules is taking up space on Mac: what to delete: Find every node_modules folder on your Mac, see which are largest, delete the ones you can reinstall, and clear the npm, pnpm and Yarn caches safely.
- Docker is taking up space on Mac: how to reclaim it: Why Docker Desktop holds tens of GB on a Mac, how to see what is inside, which prune commands are safe, and why the disk file may not shrink.