Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Uninstall brew package and dependencies

Uninstall brew package and dependencies

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
Copy link

As far as I understand it yes, that is why the last step reinstalls missing libraries.

Copy link

orrblue commented Dec 18, 2018

Note that if you installed python with homebrew for your day-to-day use, and have only 1 package that depends on python...and then you remove its dependencies and the package itself, python will be removed too. The last line of code won't reinstall python because now there are no homebrew packages that depend on it.

Copy link

mrgloom commented Feb 18, 2020

Seems deps not the same:

brew uninstall python3
Error: Refusing to uninstall /usr/local/Cellar/python/3.7.6_1
because it is required by cairo, ffmpeg, glib, harfbuzz, libass, numpy, pybind11, tbb and vim, which are currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies python3
brew deps python3

Copy link

Amar1729 commented Mar 11, 2020

Now, it may be easier to instead run:

$ brew uninstall [FORMULA]

$ brew deps [FORMULA] | xargs -n1 brew uninstall

xargs -n1 will force xargs to only take one argument at a time, so you'll have the same number of calls to `brew uninstall as number of dependencies. Then you can rely on brew to decide whether a dependency isn't required anymore (so it'll uninstaall it) or if the dep is required by something else that brew call will fail and xargs will move on.

Copy link

@mrgloom , brew deps will show what kegs a formula depends on; the uninstall error message is telling you what other formula depend on the one you're trying to uninstall (or "reverse-dependencies"). you can show these with:

$ brew uses --installed [FORMULA]

Copy link

Hey, so depending on the FORMULA that you're uninstalling this command can be quite dangerous

brew deps [FORMULA] | xargs brew remove --ignore-dependencies

If the formula has a lot of dependencies that are required for other packages, stuff get broken :(

Copy link

Amar1729 commented Apr 30, 2020

This problem is more robustly solved by something like brew rmtree

Copy link

Just a small suggestion of an improvement on that last line:

brew missing | cut -d: -f2 | tr ' ' "\n" | sort | uniq | xargs brew install

So that duplicates are really removed.

Copy link

seguri commented Dec 14, 2020

Copy link

squm commented May 16, 2021

brew autoremove

Copy link

brew autoremove

It works!

Copy link

pmsaue0 commented Jan 15, 2022

brew uninstall [formula] ; brew autoremove


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment