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
--ignore-dependencies options, but belt and braces...
I usually just do
brew remove --force $(brew list --formula)
brew remove --cask --force $(brew list)
How is this different than the accepted answer that uses a while loop?– ʀ2ᴅ2Oct 9, 2018 at 17:28
14@ʀ2ᴅ2 I think you've answered your own question there! This is much nicer to manually type in than an entire for loop.– grg ♦Oct 9, 2018 at 18:13
1@grg that's a lot of work compared to just opening up a text window, pasting the code and than calling the file. Makes it easier down the road if you want to ever do it again instead of trying to remember the command. Each their own I guess.– ʀ2ᴅ2Oct 9, 2018 at 18:22
3This is not just more compact, this is more correct. The while loop is either superfluous or indicates a scenario where the user should investigate what failed and why. The for loop is superfluous. Aug 2, 2019 at 23:09
4For the record, I’d mark this as the answer now. And I agree with @ChrisPage. Whatever I was doing at the time worked but was questionable. If I were to answer this today I would be using this answer.– forquareFeb 2, 2021 at 22:26
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.