brew Verified current stable Not installed? Package Management

Brew / Cleanup Unused Formulae

Cleanup Unused Formulae

Cleans up Homebrew and uninstalls formulae that are no longer linked.

$
Terminal
brew bundle cleanup --force

When To Use

When preparing a clean build environment after extensive package installs or removals.

Pro Tip

Run `brew cleanup --dry-run` to preview removals before actual execution.

Terminal Output

Expected runtime feedback

Simulated preview
>
Output
Removing unused formulae:

  Name                 Version   Status
  brew-cask           1.0.0    Removed
  wget                1.21.1   Removed

Cleanup completed. 2 formulae were removed.

Anatomy of Output

Understanding the result

==> Uninstalling unused formulae: package_d, package_e Packages Removed

Lists specific packages being removed.

==> Deleted 2 formulae. Cleanup Summary

Indicates the number of formulae deleted.

==> Cleanup completed successfully. Completion Message

Confirmation that the cleanup process finished.

Power User Variants

Optimized versions

brew bundle cleanup --force

Action forces the removal of previously installed formulae with no confirmation.

brew cleanup --prune=2

Prunes formulae older than two versions.

Unix Pipeline

Shell combinations

brew cleanup --dry-run

Simulates cleanup process without applying changes.

Troubleshooting

Common pitfalls

Error: Permission denied to /usr/local/bin

Solution: Ensure proper permissions for Homebrew directories.

Error: Could not find formula for package_f

Solution: Ensure that the package is indeed installed before cleanup.

Error: Cleanup failed due to locked directory

Solution: Unlock the directory or handle specific process blocking cleanup.

Command Breakdown

What each part is doing

brew
Base Command
The executable that performs this operation. Here it runs Brew before the shell applies any redirect operators.
--force
Command Option
Tool-specific option used by this command invocation.

How To Run

Execution path

  1. Step 1

    Run the command: `brew bundle cleanup --force` to remove unused formulae.

  2. Step 2

    Verify the result using: `brew list` to check if any unused formulae remain.

Alternative Approaches

Comparable commands in other tools

Alternative package management tools for the same job.