Uninstall all programs installed by Homebrew
I am wondering if there is a way to uninstall all "programs" installed by Homebrew? I was using it and installed programs that corresponded to programming or using C/C++ and used the terminal to compile it but will not be using it in a few months.
According to the homebrew FAQ, to uninstall homebrew you use:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
If you don’t want to completely uninstall home-brew but just want to remove all packages installed by homebrew, I think this will do what you need (I’m not currently in a position to remove all of my packages to check):
while [[ `brew list | wc -l` -ne 0 ]]; do
for EACH in `brew list`; do
brew uninstall --force --ignore-dependencies $EACH
done
done
This will get a list of all the installed packages and loop over them removing one at a time, ignoring any dependencies.
I’ve enclosed the whole thing in a loop double check that after the first run all of the packages have been uninstalled — I’m pretty sure they will be due to the --force
and --ignore-dependencies
options, but belt and braces...
I usually just do
brew remove --force $(brew list --formula)
and
brew remove --cask --force $(brew list)
The answers didn't work for me, but the following did (Homebrew 2.4.9, Feb 17 2021):
brew list | xargs brew uninstall --force
I also had a few casks installed, this removed them as well:
brew list --cask | xargs brew uninstall --force
Here is what I used:
for f in `brew list`; do
brew uninstall --ignore-dependencies --force $f
done
for f in `brew list --formula`; do
brew uninstall --ignore-dependencies --force $f
done
Because nowadays it requires brew list --formula
or else you will get an error
Error: Invalid usage: this command requires a formula or cask argument
Jainav@Apples-MBP ~ % brew uninstall --ignore-dependencies --force --formula
Usage: brew uninstall, rm, remove [options] formula|cask
Uninstall a formula or cask.
-f, --force Delete all installed versions of formula.
Uninstall even if cask is not installed,
overwrite existing files and ignore errors
when removing files.
--zap Remove all files associated with a cask.
May remove files which are shared between
applications.
--ignore-dependencies Don't fail uninstall, even if formula is
a dependency of any installed formulae.
--formula, --formulae Treat all named arguments as formulae.
--cask, --casks Treat all named arguments as casks.
-d, --debug Display any debugging information.
-q, --quiet Make some output more quiet.
-v, --verbose Make some output more verbose.
-h, --help Show this message.