198

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.

5 Answers 5

360

For all packages:

brew deps --tree --installed

For one package only (for example, vim)

brew deps --tree --installed vim

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.

3
  • 21
    To check only one package, e.g. brew deps --tree --installed vim. Commented Apr 1, 2021 at 22:29
  • Is there a faster way? Takes 1s. I'd like to check deps are installed everytime before running one of my clis.
    – vaughan
    Commented May 16, 2023 at 18:54
  • 1
    @NeoZoom.lua brew deps --tree <foo> is enough. Just tested brew deps --tree zstd.
    – Fonzie
    Commented Jul 7, 2023 at 6:26
94

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 --formula --for-each | sed "s/^.*:/$(tput setaf 4)&$(tput sgr0)/"

Alternate command without xargs:

brew deps --formula --for-each $(brew leaves) | sed "s/^.*:/$(tput setaf 4)&$(tput sgr0)/"
1
  • 1
    Thanks a lot! I'm clearing space on my Mac and this is helpful. Commented Mar 30 at 9:38
57

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.

3
  • 10
    Is there no way to also see which packages depend on the installation you are getting info for?
    – oliver
    Commented Dec 8, 2016 at 0:44
  • 55
    @OliverDechant You want brew uses --installed {formula}.
    – Vic
    Commented Aug 6, 2020 at 7:48
  • 2
    brew info doesn't show you dependencies of dependencies, whereas brew deps --tree does.
    – gregory
    Commented Sep 10, 2023 at 22:54
29

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.

0
23

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
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.