Secwall's notes

A little brew helper to remove non needed formulas

Posted on


One of the annoying things about the Homebrew package manager are garbage dependencies. Sometimes, a formula switches from a source-only version to a bottle, so its build dependencies are no longer required. Sometimes, a formula simply switches from one library to another.

Let's take one example: the include-what-you-use formula depends on llvm. If you run brew upgrade at a time when llvm already has version N, but include-what-you-use still depends on version N-1, you will end up with two versions of llvm. Some time will go by, and include-what-you-use will depend on llvm version N.

So, what now? Do we need llvm N-1? There's an easy way to check: just try removing it and homebrew will tell you.

But I like to see which formulas are not used as dependencies in my system using some simple command.


So I wrote a little helper for this task. Here is how to use it:

$ brew-helper list
llvm@16 <- here is an old version of llvm (at the moment of this writing the current version is 17)

Let's get rid of it:

$ brew-helper rm-dep llvm@16
Removing llvm@16
Found new unused dep: six
Removing six

As you can see, after the removal of llvm@16, a new garbage dependency has appeared (six). And our helper has gotten rid of it too.

Hope you find it usefull.