Easy way to have Homebrew list all package dependencies

HomebrewDependency Management

Homebrew Problem Overview


Is there anyway to have the command brew show all the installed or optional dependencies for any given package? It would also be helpful to see which of the install packages are themselves the dependencies of others packages.

Homebrew Solutions


Solution 1 - Homebrew

For all packages:

brew deps --tree --installed

For one package only (e.g.):

brew deps --tree --installed vim

Thanks to rob-kovacs for suggesting the --tree addition

See this helpful article for details: https://blog.jpalardy.com/posts/untangling-your-homebrew-dependencies/ Especially if you're interested in creating a graph of the dependency tree.

Solution 2 - Homebrew

Here is a command that will list all formulas that aren't dependents of any other formulas (leaves), and for each of them lists all of its dependencies.

Sample output line:

awscli: gdbm readline sqlite tcl-tk xz

Command:

brew leaves | xargs brew deps --installed --for-each | sed "s/^.*:/$(tput setaf 4)&$(tput sgr0)/"

Solution 3 - Homebrew

You can use info command like.

brew info ffmpeg

It will show you information and dependencies of formula. Also, it shows if this package installed by a tick after name of it.

Solution 4 - Homebrew

I found the brew deps --tree switch is also very helpful to visualize dependencies just in the command line. From the official doc:

brew deps --tree [--1] [filters] [--annotate] (formulae|--installed):
Show dependencies as a tree. When given multiple formula arguments, output
individual trees for every formula.

Example1:

brew deps --tree fontconfig

Output1:

fontconfig
└── freetype
    └── libpng

Example2:

brew deps --tree --1 fontconfig

Output2:

fontconfig
└── freetype

and there are more switches explained by:

brew help deps

Solution 5 - Homebrew

Command:

brew deps --include-build --tree $(brew leaves)

Convenient alias:

alias brewdeps="brew leaves | xargs brew deps --include-build --tree"

This way you will get dependencies printed hierarchically and each package will be printed only once.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionoliverView Question on Stackoverflow
Solution 1 - HomebrewEric DobbsView Answer on Stackoverflow
Solution 2 - HomebrewGustavo SeidlerView Answer on Stackoverflow
Solution 3 - HomebrewtanaydinView Answer on Stackoverflow
Solution 4 - Homebrewphe0113View Answer on Stackoverflow
Solution 5 - HomebrewEugene MaysyukView Answer on Stackoverflow