How can I remove outdated versions of Homebrew packages that are installed side-by-side with current versions?
3 Answers
The cleanup (brew cleanup
) command will remove outdated installed package versions. To affect a particular package/formula, you may supply a formula name like so: brew cleanup $FORMULA
. To simulate cleanup, i.e. see what would be removed, you may use the -n
option: brew cleanup -n
.
-
39For the record:
brew cleanup
only cleans outdated package versions if you have the newest version installed, so firstbrew upgrade
thenbrew cleanup
– JanOct 14, 2016 at 14:15 -
43
-
43
@aknuds1 is right about brew cleanup
so I'll just add that I have an alias in my ~/.profile
that does all my brew-related cleanup, including cask update/cleanup
alias brewski='brew update && brew upgrade && brew cleanup; brew doctor'
I end with brew doctor
to make sure all packages are correctly symlinked, e.g., awscli
seems to have a problem with this on the regular so I constantly have to unlink/relink. Hope this helps.
EDIT: As it was pointed out to me in the comments, brew cask
functionality has been merged into the homebrew core. These commands were also throwing errors, so references to brew cask
have been deleted.
EDIT2: As I run this daily, I noticed the following comment today. I've updated the command accordingly
Warning: We decided to not change the behaviour of `brew upgrade` so
`brew upgrade --all` is equivalent to `brew upgrade` without any other
arguments (so the `--all` is a no-op and can be removed).
-
3You don't need to do
brew upgrade brew-cask
anymore as since this pull requestbrew update
will also now upgrade homebrew-cask automatically.– LantrixJul 12, 2016 at 6:20 -
1@Lantrix Thanks for that update. I've edited my answer to reflect this change.– SaxDaddyJul 12, 2016 at 15:28
-
3
brew upgrade --cleanup
will remove old packages as new packages are installed.– ZenexerJan 31, 2018 at 5:45 -
I dont advise to use
brew upgrade
but instead to usebrew outdated
and then upgrade each one of the packages bybrew upgrade PACKAGE
that way you have more control Mar 24, 2018 at 11:13 -
1
brew upgrade
runsbrew update
before looking for package updates. Thus,brew update
is unnecessary.– MCCCSMay 3, 2018 at 12:41
Just for the records, you can clean the outdated versions of the packages that you are about to upgrade using the --cleanup flag:
brew upgrade --cleanup <package_name>