The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,157 other followers

How to remove all old and outdated brew packages on MacOS – nixCraft

Posted by jpluimers on 2020/10/19

I was not aware that brew install,  brew cask install, brew update and brew upgrade would keep all the older versions on disk, so I was a bit amazed that OmniDiskSweeper and GrandPerspective found over 20 gigabytes of cruft in /usr/local/Cellar and a bit in /Library/Caches/Homebrew.

Based on [WayBack] How to remove all old and outdated brew packages on MacOS – nixCraft and [WayBack] homebrew – brew: how to delete outdated version of package – Ask Different (which have more info) I changed the order a bit:

alias brew-cleanup-update-ugprade='brew cleanup && brew update && brew upgrade'

You can use brew pin to keep specific versions (and brew unpin to release them so you get the most recent one).

The main reason people do not bump into brew cleanup is that it is not advertised as a command:

# brew --help
Example usage:
  brew search [TEXT|/REGEX/]
  brew info [FORMULA...]
  brew install FORMULA...
  brew update
  brew upgrade [FORMULA...]
  brew uninstall FORMULA...
  brew list [FORMULA...]

Troubleshooting:
  brew config
  brew doctor
  brew install --verbose --debug FORMULA

Contributing:
  brew create [URL [--no-fetch]]
  brew edit [FORMULA...]

Further help:
  brew commands
  brew help [COMMAND]
  man brew
  https://docs.brew.sh

But it is there and has help as well:

# brew cleanup --help
brew cleanup [--prune=days] [--dry-run] [-s] [formulae|casks]:
    Remove stale lock files and outdated downloads for formulae and casks,
    and remove old versions of installed formulae. If arguments are specified,
    only do this for the specified formulae and casks.

    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, including downloads for even the latest
    versions. Note downloads for any installed formula or cask will still not
    be deleted. If you want to delete those too: rm -rf "$(brew --cache)"

On pin and unpin:

# brew pin --help
Usage: brew pin formulae

Pin the specified formulae, preventing them from being upgraded when
issuing the brew upgrade formulae command. See also unpin.

    -d, --debug                      Display any debugging information.
    -h, --help                       Show this message.
# brew unpin --help
Usage: brew unpin formulae

Unpin formulae, allowing them to be upgraded by brew upgrade formulae.
See also pin.

    -v, --verbose                    Make some output more verbose.
    -d, --debug                      Display any debugging information.
    -h, --help                       Show this message.

–jeroen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: