How do I reinstall all packages installed with Homebrew?
Solution 1
It's as simple as that:
$ brew list | xargs brew reinstall
You don't need to uninstall anything, because doing so you may lose your settings and configs.
Solution 2
to keep not only installed brews but also casks and taps i recommend to
$ brew bundle dump --describe --global
$ brew bundle install --global
the first command will write ~/.Brewfile which will be read again in the second call. it looks like this:
$ cat ~/.Brewfile
tap "buo/cask-upgrade"
tap "homebrew/cask-fonts"
brew "direnv"
brew "python"
cask "0xed"
cask "alacritty"
please issue
$ brew bundle -h
for more details on the bundle command.
Solution 3
I ran into a need for this after upgrading to OSX High Sierra. Most of the brew packages were failing form missing dylibs. Ended up writing a quick & dirty script that cleanly removes & replaces one at a time, ignoring dependencies so you don't force bulk purges. You need to fix each stopping point, but it picks up where it left off so it's not too painful.
YMMV as always
#!/bin/bash -e
if [ "$1" == "-h" ] ; then
cat <<EOT
Remove & reinstall all brew owned packages
Fail on error to allow manual fixing
Accept package name as arg1 to spec pick up point.
$0 [<pickup point>]
eg:
$0
or
$0 ctags
where <ctags> is the package to start from
EOT
exit 1
fi
for l in $(brew list) ; do
if [ "$1" ] ; then
if [[ $l < $1 ]] ; then
echo "skipping $l"
continue
fi
fi
echo "Remove $l"
brew uninstall --ignore-dependencies $l
echo "Re-add $l"
brew install $l
done
Related videos on Youtube
JAL
Updated on September 18, 2022Comments
-
JAL 3 monthsI recently had an issue where all of my linked binaries were removed from
/usr/local/bin/. Fortunately, most of these were just dynamic links to binaries installed with Homebrew, so after reinstalling Homebrew I need to get them back. Is there a way to force reinstall all installed packages and binaries with Homebrew? Maybe piping the output ofbrew listintobrew reinstall? -
JAL about 6 yearsI could, but then I would have to manually enter every package name frombrew list. I need an automated solution that automatically pulls frombrew listand reinstalls all packages. -
JAL about 6 yearsI had to remove a few problem formulae, but this did the trick. Thanks! -
New Alexandria almost 4 yearsworks except for casks -
ryanjbonnell about 2 yearsThe maintainers of HomeBrew now recommend adding--formulato only list formulae, making the updated command$ brew list --formula | xargs brew reinstall(as of November 2020). -
Jason almost 2 yearsDoes anyone know if running the brew uninstall script will delete the casks that were installed by homebrew? I know that running "brew uninstall --cask [caskname]" will delete the cask, but the uninstall script doesn't say whether it will delete all the installed casks as well.