LinuxCommandLibrary

brew-autoremove

Remove unneeded Homebrew dependencies

TLDR

Remove all unused formulae

$ brew autoremove
copy

Print what would be removed, but don't actually remove anything
$ brew autoremove [[-n|--dry-run]]
copy

SYNOPSIS

brew-autoremove [options]

PARAMETERS

--dry-run
    Performs a simulation of the removal process, showing which formulae would be uninstalled without actually removing them. This is useful for previewing changes.

--verbose, -v
    Displays more detailed information about the operations being performed, including formulae being considered for removal.

DESCRIPTION

The command brew-autoremove is not a standard, built-in Homebrew command. Instead, it typically refers to a user-created alias or an external script designed to replicate the functionality of package managers like `apt autoremove` on Linux, which automatically removes packages that were installed as dependencies and are no longer required by any currently installed software.

For Homebrew, the core functionality for cleaning up unused dependencies is provided by the `brew cleanup` command, specifically when used with the `--prune=all` option. When a Homebrew formula is installed, it may pull in other formulae as dependencies. If the main formula is later uninstalled, its dependencies might remain on the system. The purpose of `brew-autoremove` (or `brew cleanup --prune=all`) is to identify these orphaned dependencies—those not explicitly installed by the user and no longer depended upon by any active formula—and remove them. This helps to free up disk space and keep the Homebrew installation tidy. Users often create `brew-autoremove` as a convenience to simplify regular system maintenance.

CAVEATS

The most significant caveat is that brew-autoremove is not a native Homebrew command. Users typically implement it as an alias (e.g., `alias brew-autoremove='brew cleanup --prune=all'`) or a custom shell script. While the underlying Homebrew mechanisms are robust, misconfigurations or reliance on outdated scripts can lead to unexpected behavior. There's a slight risk of removing dependencies that a user might indirectly rely on if they were not explicitly installed or if Homebrew's dependency tracking has edge cases. Always use `--dry-run` or review the output carefully before proceeding with actual removal, especially with custom scripts. It's recommended to use the official brew cleanup --prune=all command directly for the most reliable behavior.

HOMEBREW'S OFFICIAL APPROACH TO DEPENDENCY PRUNING

Homebrew maintains a dependency graph for all installed formulae. When a formula is uninstalled, its dependencies are not immediately removed. The `brew cleanup` command, particularly with the `--prune=all` option, is the official Homebrew method to identify and remove these orphaned dependencies. It checks if any installed formulae still require a particular dependency. If not, and the dependency was installed solely due to another formula, it's marked for removal. This process ensures that only truly unused components are uninstalled, maintaining system stability while freeing up disk space.

CREATING A `BREW-AUTOREMOVE` ALIAS

Users often create a shell alias to make `brew-autoremove` available as a command. A common way to do this is by adding a line like `alias brew-autoremove='brew cleanup --prune=all'` to your shell's configuration file (e.g., `~/.bashrc`, `~/.zshrc`, `~/.profile`). After reloading your shell configuration (e.g., `source ~/.zshrc`), you can simply type `brew-autoremove` to perform the cleanup operation.

HISTORY

The concept of `autoremove` became popular with package managers like APT on Debian/Ubuntu, where it simplifies system maintenance by automatically removing unused dependencies. As Homebrew grew in popularity on macOS and Linux, users often sought a similar convenient command. While Homebrew's `cleanup` command initially focused on removing old versions and cached downloads, its functionality was later extended to include dependency pruning with the `--prune=all` option. The name `brew-autoremove` emerged as a common user-created alias or external script to encapsulate this specific cleanup operation, mimicking the familiar `autoremove` pattern from other Linux distributions. Its usage reflects a desire for a straightforward command to keep Homebrew environments lean.

SEE ALSO

brew(1), brew-cleanup(1), apt-autoremove(8), dnf-autoremove(8)

Copied to clipboard