LinuxCommandLibrary

brew-leaves

List Homebrew leaf packages

TLDR

List installed formulas that are not dependent on other installed formulas or casks

$ brew leaves
copy

Only list leaves that were manually installed
$ brew leaves [[-r|--installed-on-request]]
copy

Only list leaves that were installed as dependencies
$ brew leaves [[-p|--installed-as-dependency]]
copy

Display help
$ brew leaves [[-h|--help]]
copy

SYNOPSIS

brew leaves [options]

PARAMETERS

--installed-on-request
    List only formulae explicitly installed on request, excluding auto-installed dependencies

--formula
    List only formulae (default behavior)

--cask
    List only cask leaves (GUI applications)

-q, --quiet
    Suppress all output except the list

-v, --verbose
    Print verbose progress information

-d, --debug
    Enable debug output for troubleshooting

-h, --help
    Show help message and exit

--version
    Display version information

DESCRIPTION

The brew leaves command is a utility within Homebrew, the popular package manager for macOS and Linux. It identifies and lists all locally installed formulae (packages) that are not dependencies of any other installed formulae. In the dependency graph—where an arrow from formula A to B indicates A depends on B—these 'leaves' are nodes with no incoming arrows from other installed formulae. They represent top-level packages installed directly by the user or as explicit dependencies, not serving as requirements for others.

This is useful for cleaning up unused packages, auditing installations, or understanding the structure of your Homebrew cellar. For example, core tools like git or wget might appear if nothing else depends on them. By default, it lists all such leaves, but options allow filtering to explicitly requested installs or separating formulae from casks (GUI apps).

On Linux, it functions via Linuxbrew or official Homebrew support (since 2020), scanning the $HOMEBREW_PREFIX cellar. Output is one formula per line, making it script-friendly for automation like bulk uninstallation with brew uninstall $(brew leaves). It's efficient, querying the local database without network access.

CAVEATS

Requires Homebrew installation; results depend on current cellar state. Does not consider pinned formulae or external dependencies. On Linux, ensure $HOMEBREW_PREFIX is properly set.

EXAMPLE USAGE

brew leaves
git
node

brew leaves --installed-on-request
Lists only explicitly requested leaves.

brew uninstall --ignore-dependencies $(brew leaves)
Safely removes all leaves.

OUTPUT NOTES

One formula/cask per line. Pipe to grep or sort for filtering. No colors by default; respects BREW_NO_COLOR.

HISTORY

Introduced in early Homebrew versions around 2010 by Max Howell. Evolved with Linux support in Linuxbrew (2014, later merged into Homebrew core in 2020). Enhanced with --installed-on-request in Homebrew 1.1.0 (2017) for better user-request filtering.

SEE ALSO

brew(1), brew-list(1), brew-deps(1), brew-graph(1)

Copied to clipboard