Untangling Your Homebrew Dependencies
Does this look familiar?
Wait, what? When did this happen?!
You can try looking at the
brew ls output and try to remember what you
installed when. Your next reflex is probably to search “homebrew dependencies”
because there must be an easy solution…
What are vim’s dependencies?
Hmmm… what depends on perl?
How can I see all dependencies?
The Real Question: What Can I Uninstall?
You can uninstall packages no other packages depend on. Thankfully, there’s a command for that:
but here’s some bad news…
brew leaves is broken!
but, if you remember from above:
brew leaves tells you nobody uses perl, but
brew uses confirms that vim uses perl…
Detour: Dependencies and Requirements
Let’s look at vim info:
There are two sections: “dependencies” and “requirements” … so, what’s the difference?
dependency: a "real" package you depend on requirement: an "alias" for one of multiple substitute packages
For example: vim needs perl, but it’s not picky about which perl is installed.
brew search perl, you’ll find you have many options; all of which
satisfy vim’s “requirement”.
Brew Leaves is Broken
To make a long story short,
brew leaves only lists dependencies (but not
There are a bunch of homemade solutions
out there. I went through homebrew’s code and
brew deps --installed is the
complete source of truth.
A leaf is a package that never shows up on the right side of the colon.
If you feel that the output of
brew deps --installed is not friendly, you’re not alone.
brew-graph is a ruby script that uses the output of
brew deps --installed and generates a graph, in GraphViz or GraphML format. After you install brew-graph, you can visualize your dependencies:
I think you can get better results by using
fdp, instead of
generate the image.
fdp is already installed if
dot is installed; they are
both part of GraphViz. The man page says:
… fdp draws undirected graphs using a ‘‘spring’’ model. It relies on a force-directed approach in the spirit of Fruchterman and Reingold …
I would also recommend the new
--highlight-leaves option to color (in gray) packages that can be uninstalled: