Skip to content

Instantly share code, notes, and snippets.

Embed
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
@mhaeussermann

This comment has been minimized.

Copy link

@mhaeussermann mhaeussermann commented Dec 18, 2018

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

@orrblue

This comment has been minimized.

Copy link

@orrblue 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.

@mrgloom

This comment has been minimized.

Copy link

@mrgloom 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
gdbm
openssl@1.1
readline
sqlite
xz
@Amar1729

This comment has been minimized.

Copy link

@Amar1729 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.

@Amar1729

This comment has been minimized.

Copy link

@Amar1729 Amar1729 commented Mar 11, 2020

@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]
@brifordwylie

This comment has been minimized.

Copy link

@brifordwylie brifordwylie commented Apr 28, 2020

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 :(

@Amar1729

This comment has been minimized.

Copy link

@Amar1729 Amar1729 commented Apr 30, 2020

This problem is more robustly solved by something like brew rmtree

@ianribas

This comment has been minimized.

Copy link

@ianribas ianribas commented Jul 16, 2020

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.

@seguri

This comment has been minimized.

Copy link

@seguri seguri commented Dec 14, 2020

@squm

This comment has been minimized.

Copy link

@squm squm commented May 16, 2021

brew autoremove

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