brew Verified current stable Not installed? Package Management

Brew / Cleanup All Packages

Cleanup All Packages

Remove all outdated versions of installed packages in Homebrew.

$
Terminal
brew cleanup

When To Use

When ensuring the environment is up to date and minimizing storage consumption by removing legacy packages.

Pro Tip

Integrate with cron jobs to automate cleanup at specified intervals for continuous maintenance.

Terminal Output

Expected runtime feedback

Simulated preview
>
Output
==> Cleaning up /usr/local/Cellar...
Removing: /usr/local/Cellar/package1, version 1.0.0
Removing: /usr/local/Cellar/package2, version 2.3.5
==> Cleaning up Homebrew's cache:
removed 5 files from /Users/user/Library/Caches/Homebrew

Anatomy of Output

Understanding the result

Cleanup summary: 10 total packages cleaned up. Cleanup Summary

Indicates the total number of packages removed.

- oldpackage1 (v1.0.0) Removed Package

Lists specific outdated packages that were cleaned.

Freed up: 150MB. Disk Space Freed

Quantifies the storage reclaimed.

Power User Variants

Optimized versions

brew cleanup --force

Remove all outdated packages without confirmation.

brew cleanup --dry-run

Display what would be removed without executing.

Troubleshooting

Common pitfalls

Error: No packages out-of-date.

Solution: Run 'brew outdated' to check for any outdated packages.

Failed to execute cleanup

Solution: Verify Homebrew installation and repositories; refresh if necessary.

Permission Denied

Solution: Execute with appropriate permissions to access Homebrew directories.

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.

How To Run

Execution path

  1. Step 1

    Run the command: brew cleanup

  2. Step 2

    Verify cleanup by checking the cache size: du -sh /Users/user/Library/Caches/Homebrew

  3. Step 3

    Ensure that unneeded packages are listed no longer with: brew list

Alternative Approaches

Comparable commands in other tools

Alternative package management tools for the same job.