Brew Cleanup

Brew cleanup frees up space in macOS and Linux devices by removing old versions of formulae and small kegs of data. Let’s look at sample instructions:

Remove a Formula

$ brew cleanup <formula>

# clean everything up at once
$ brew cleanup

We can access “help” using -h.

$ brew cleanup -h

brew cleanup [--prune=days] [--dry-run] [-s] [formulae]:
    For all installed or specific formulae, remove any older versions from the cellar. In addition, old downloads from the Homebrew download-cache are deleted.

    If --prune=days is specified, remove all cache files older than days.

    If --dry-run or -n is passed, show what would be removed, but do not
    actually remove anything.

    If -s is passed, scrub the cache, removing downloads for even the latest
    versions of formulae. Note downloads for any installed formulae will still
    not be deleted. If you want to delete those too: rm -rf $(brew --cache)

Command -prune=days can clear caches of some days N earlier. If the number of days is​ not provided, then it will clear caches of the previous 14 days.

Command s can be used to clean the latest formula.