Removing all Homebrew stuff

By

How I removed every Homebrew package to free up space, using brew remove --force with brew list to wipe all formulae and casks, then reinstalled what I needed.

~~~

Stuff just accumulates over time.

I looked into the /opt/homebrew/Cellar folder, which holds all the Homebrew packages, and it was 10GB.

So I found this suggestion and ran:

brew remove --force $(brew list --formula)

and then

brew remove --cask --force $(brew list)

to remove all commands and apps installed through Homebrew.

Then I reinstalled just the things I needed.

How the commands work

brew list --formula prints every formula you have installed, meaning the command line tools.

The $(...) syntax is command substitution: the shell runs the inner command first, then passes its output as arguments to the outer one. So the first command expands to something like brew remove --force wget node ffmpeg ..., with your entire list of packages in it.

The --force flag removes all installed versions of each formula without asking for confirmation. With dozens of packages to remove, you want that.

The second command repeats the operation for casks, the GUI apps you installed with brew install --cask.

Don’t forget the cache

Removing the packages is not the whole story. Homebrew keeps downloaded archives in a cache folder, and after years of upgrades that folder gets big too.

Run this to clean it:

brew cleanup -s

The -s flag scrubs the cache, including the downloads for the packages you still have installed.

Watch out for tools you rely on

Here’s the pitfall: this removes everything. If you installed git, node, or even your shell through Homebrew, those disappear too, and you notice at the worst possible moment.

Before wiping, save the list of what you had:

brew list > ~/brew-packages.txt

Even better, look at brew leaves first. It prints only the formulae you installed on purpose, leaving out the dependencies they pulled in. That’s usually the exact list you want to reinstall from.

In my case starting from scratch was the whole point. Most of those 10GB were things I had tried once and forgotten about, so I removed everything and reinstalled the two or three tools I use daily.

Tagged: Mac · All topics
~~~

Related posts about mac: