15

I'm trying out Homebrew, but I can't seem to figure out when uninstalling a 'formula', how to recursively remove the dependencies as well. I.e. Macports is:

$ port uninstall --follow-dependencies <portname>

How does this work with Homebrew?

5 Answers 5

9

A simple way to solve the problem of accumulating dependencies of deinstalled things is to periodically run brew leaves and compare it against a list of wanted leaves, and recursively remove everything else.

The following works, but of course is not very readable:

1) Show all the leaves minus the ones in your wanted list:

$ brew leaves | egrep -v 'bcwipe|brew-cask|lftp|mmv|mobile-shell|mplayer|node|octave|python|zsh'

2) Once you have adjusted the list (i.e. added new keepers), get rid of the rest:

$ brew uninstall `brew leaves|egrep -v 'bcwipe|brew-cask|git|lftp|mmv|mobile-shell|mplayer|node|octave|python|zsh'`

This usually has to be called a few times in a row to get them all, and the final call should be followed by a

$ brew cleanup

To beautify a bit, the list of keepers can of course be kept in a file somewhere.

2
  • If you assumed everything in /usr/local/bin was tied to a "wanted" item, you might be able to programmatically generate the wanted list. You'd miss pure library installations, but maybe easier than maintaining a hand list of wanted items.
    – Ian C.
    May 19, 2014 at 21:08
  • Very simple solution
    – minseong
    Mar 22, 2021 at 18:32
4

Like @Adam Vandenberg said, there's no easy way to do it.

However, I filed an issue on Homebrew's GitHub page, and it appears there's a workaround to solve this, until they add an exclusive command.

See my answer on StackOverflow for more info.

1
  • Is the exclusive command developed yet?
    – Nimesh Neema
    Sep 11, 2018 at 10:38
4

In 2021, you can now use brew autoremove: https://docs.brew.sh/Manpage#autoremove---dry-run

2

Unfortunately, Homebrew does not track dependencies in this way.

1

I just wrote a small wrapper script to add this functionality to brew. Source it in your .bashrc and it will track which packages you install, then recursively remove unneeded dependencies when you uninstall.

https://github.com/DaemonF/brew-recursive-uninstall

You must log in to answer this question.