I have a Homebrew formula that I wish to uninstall/remove along with all its dependencies, skipping packages whom other packages depend upon (a.k.a. Cascadi
Based on @jfmercer answer (corrections needed more than a comment).
Remove package's dependencies (does not remove package):
brew deps [FORMULA] | xargs brew remove --ignore-dependencies
Remove package:
brew remove [FORMULA]
Reinstall missing libraries:
brew missing | cut -d: -f2 | sort | uniq | xargs brew install
Tested uninstalling meld
after discovering MeldMerge releases.
Using this answer requires that you create and maintain a file that contains the package names you want installed on your system. If you don't have one already, use the following command and delete the package names what you don't want to keep installed.
brew leaves > brew_packages
Then you can remove all installed, but unwanted packages and any unnecessary dependencies by running the following command
brew_clean brew_packages
brew_clean
is available here: https://gist.github.com/cskeeters/10ff1295bca93808213d
This script gets all of the packages you specified in brew_packages and all of their dependancies and compares them against the output of brew list
and finally removes the unwanted packages after verifying this list with the user.
At this point if you want to remove package a
, you simply remove it from the brew_packages file then re-run brew_clean brew_packages
. It will remove b
, but not c
.
The goal here is to remove the given package and its dependencies without breaking another package's dependencies. I use this command:
brew deps [FORMULA] | xargs brew remove --ignore-dependencies && brew missing | xargs brew install
Note: Edited to reflect @alphadogg's helpful comment.
You can just use a UNIX pipe for this
brew deps [FORMULA] | xargs brew rm