Skip to content

Instantly share code, notes, and snippets.

@gdalmau
Created August 2, 2023 10:10
Show Gist options
  • Save gdalmau/bc380335049ee602d5b63ebfd05a7c0d to your computer and use it in GitHub Desktop.
Save gdalmau/bc380335049ee602d5b63ebfd05a7c0d to your computer and use it in GitHub Desktop.
Useful brew commands

brew deps

See the dependency tree for anything you installed:

> brew deps node --tree

node
├── brotli
├── c-ares
├── icu4c
├── libnghttp2
├── libuv
├── openssl@1.1
│   └── ca-certificates
└── python@3.9
    ├── gdbm
    ├── mpdecimal
    ├── openssl@1.1
    │   └── ca-certificates
    ├── readline
    ├── sqlite
    │   └── readline
    └── xz

brew uses

See which other formulas use the one installed:

> brew uses readline --installed

node            python@3.9            sqlite

The --installed flag is important, because without it the above command will list everything that uses the specified formula, whether it is installed on your system or not. Notice also how brew uses is recursive (in the opposite direction as brew deps), showing both python@3.9 which uses readline directly, and node, which uses it indirectly.

brew desc or brew info

Describe what the installed dependency do with brew desc, or see the full information with brew info

> brew desc pcre2

pcre2: Perl compatible regular expressions library with a new API
> brew info pcre2

==> pcre2: stable 10.42 (bottled), HEAD
Perl compatible regular expressions library with a new API
https://www.pcre.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/pcre2.rb
License: BSD-3-Clause
==> Options
--HEAD
	Install HEAD version
==> Analytics
install: 76,143 (30 days), 306,338 (90 days), 473,263 (365 days)
install-on-request: 714 (30 days), 3,113 (90 days), 5,224 (365 days)
build-error: 13 (30 days)

brew leaves

Use brew leaves -r to display a short list of what you specifically installed.

> brew leaves -r

git
less
node
sqlite

brew leaves lists things installed that aren't dependencies, and the -r filters the list to those thing you installed manually. I say "most cases" because it won't include things that you installed manually, but then also became a dependency of something you installed afterwards. This is not common.

brew bundle dump --file -

Though this is a harder command to remember (create an alias!), it gives a more reliable, complete answer than brew leaves -r:

> brew bundle dump --file -

brew "git"
brew "less"
brew "node"
brew "sqlite"
cask "rar"

It's more complete because unlike brew leaves it will include things you installed that also happened to be a dependency of something else you installed later. In addition, it includes taps and casks.

brew autoremove

brew autoremove will recursively remove all of the formulae that were not manually installed. Essentially all of the ones listed in brew leaves -p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment