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