Inspecting installed packages in Homebrew

Piotr Pliszko

Recently, I did a little cleanup on my Mac, and when I checked my Homebrew packages, the list turned out to be much longer than I expected. So, I started inspecting what I had installed manually and what is a dependency, what is still needed and what could be removed. If you would like to know some tools that helped me with this, follow along with this post.

Listing installed packages

To list all packages installed by Homebrew, use ls (or list) command.

# listing all installed packages
brew ls

# listing installed casks
brew ls --cask

# listing installed formulaes
brew ls --formulae

Sorting packages by modification type

To display the package list in a long format we can use the l flag - it will show the modification date alongside some other information. In combination with the t flag, we will sort packages by time modified.

❯ brew ls -lt
==> Formulae
total 0
drwxr-xr-x  3 piotrpliszko  admin  96 Oct 13 16:05 tree-sitter
drwxr-xr-x  3 piotrpliszko  admin  96 Oct 13 16:05 ruby-build
drwxr-xr-x  3 piotrpliszko  admin  96 Oct 13 16:05 tesseract
drwxr-xr-x  3 piotrpliszko  admin  96 Oct 13 16:05 [email protected]
# ...
Remember that this is a modification time, not an installation time.

Getting information about a package

When we have a package we would like to inspect, we can use the desc and info commands.

To get a short description of what is a package, use brew desc <package_name>. For example:

❯ brew desc go
go: Open source programming language to build simple/reliable/efficient software
❯ brew desc x264
x264: H.264/AVC encoder

To get more information about a particular package, use brew info <package_name>.

❯ brew info go
==> go: stable 1.23.2 (bottled), HEAD
Open source programming language to build simple/reliable/efficient software
https://go.dev/
Installed
/opt/homebrew/Cellar/go/1.23.2 (13,234 files, 268.2MB) *
  Poured from bottle using the formulae.brew.sh API on 2024-10-06 at 10:01:17
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/g/go.rb
License: BSD-3-Clause
==> Options
--HEAD
	Install HEAD version
==> Caveats
Homebrew's Go toolchain is configured with
  GOTOOLCHAIN=local
per Homebrew policy on tools that update themselves.
==> Analytics
install: 81,282 (30 days), 271,598 (90 days), 1,084,179 (365 days)
install-on-request: 61,528 (30 days), 203,070 (90 days), 795,853 (365 days)
build-error: 210 (30 days)

Getting package dependencies

To get all package dependencies, we will use the deps command.

❯ brew deps webp
giflib
jpeg-turbo
libpng
libtiff
lz4
xz
zstd

You can also use a --tree flag to get a detailed tree of dependencies, with nested dependencies nicely displayed.

❯ brew deps webp --tree
webp
├── giflib
├── jpeg-turbo
├── libpng
└── libtiff
    ├── jpeg-turbo
    ├── xz
    └── zstd
        ├── lz4
        └── xz

Getting common dependencies

To see if any dependency is shared between two (or more) packages, use brew deps <first_package> <second_package>.

# show the intersection of dependencies between ffmpeg and bpytop packages
❯ brew deps ffmpeg bpytop
ca-certificates
mpdecimal
readline
sqlite
xz

# you can also pass more than two package names, let's add bat package
❯ brew deps ffmpeg bpytop bat
ca-certificates

Check what uses a package

If you want to know which packages depend on a particular package, the uses command comes in handy. To check what packages use a package, use brew uses <package_name> --installed.

❯ brew uses sqlite --installed
bpytop       cairo        ffmpeg       glib         [email protected]  tesseract

Get packages installed explicitly

To list installed formulae that are not dependencies of another installed package, we can use the leaves command. By adding the r (or --installed-on-request) flag, we will filter out leaves that were manually installed

❯ brew leaves -r
bat
bpytop
cocoapods
eza
ffmpeg
fzf
# ...
If you have any questions or feedback, feel free to reach out to me on GitHub, X or LinkedIn!