Packages installed using Homebrew are all installed in a specific folder. Typically it's /usr/local/Cellar . If you don't find this folder, run brew --prefix to find the correct folder prefix. On my system, this command returned /usr/local , the place where the Cellar folder can be found.
brew provides commands for getting common types of information out of the system. brew list shows installed formulae. brew deps foo shows the dependencies that foo needs. Additional commands, including external commands, can of course be written to provide more detailed information.
By default, Homebrew will install all packages in the directory /usr/local/Cellar/ , and also creates symbolic links at /usr/local/opt/ and /usr/local/bin/ (for executable files).
For instance, when you do brew install git , you add git executable and gettext and pcre2 as dependencies. Unfortunately, when you reverse this process with brew uninstall git , the main formula disappears, but you end up with two no longer needed dependencies.
Use brew leaves
: show installed formulae that are not dependencies of another installed formula.
$ brew deps --installed
tmux: pkg-config libevent
q:
gdbm:
libxml2:
asciidoc: docbook
libevent:
pkg-config:
pcre:
docbook:
zsh: gdbm pcre
readline:
emacs: pkg-config
This seems to give us a list of all installed formulae including their dependencies. We can build a list of all formulae and a list of all dependencies and subtract the dependencies from the list of formulae, this should give us a list of formulae which are not dependencies of other formulae:
$ cat brew-root-formulae.sh
#!/bin/sh
brew deps --installed | \
awk -F'[: ]+' \
'{
packages[$1]++
for (i = 2; i <= NF; i++)
dependencies[$i]++
}
END {
for (package in packages)
if (!(package in dependencies))
print package
}'
.
$ ./brew-root-formulae.sh
zsh
asciidoc
libxml2
readline
tmux
q
emacs
Is this the output you are after?
The question is quite old, but actually only this answer resolves the issue. However, it's more like a workaround. But there's one more solution available out-of-the-box in brew
:
brew bundle dump --file -
From docs:
brew bundle dump:
Write all installed casks/formulae/images/taps into a Brewfile in the
current directory.
and the flag:
--file
Read the Brewfile from this location.
Use --file=- to pipe to stdin/stdout.
As a result we get e.g.:
tap "homebrew/bundle"
tap "homebrew/cask"
tap "homebrew/cask-fonts"
tap "homebrew/core"
tap "homebrew/services"
tap "jesseduffield/lazydocker"
tap "jesseduffield/lazygit"
brew "lazydocker"
brew "lazygit"
cask "font-sauce-code-pro-nerd-font"
If you e.g. need a pure list of formulae and casks, without taps, you can just run:
brew bundle dump --file - | grep '^brew\|^cask' | sed 's/.* "\(.*\)".*$/\1/'
and get:
lazydocker
lazygit
font-sauce-code-pro-nerd-font
P.S. If you actually save the output to the file (with brew bundle dump
or brew bundle dump --file PATH_TO_FILE
), you can easily install all the dependencies from it with brew bundle install
:
brew bundle [install]:
Install and upgrade (by default) all dependencies from the Brewfile.
You can specify the Brewfile location using --file or by setting the
HOMEBREW_BUNDLE_FILE environment variable.
this shows installed formulas as a tree.
brew deps --installed --tree
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With