How do I reinstall all packages installed with Homebrew?

18,589

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
Share:
18,589

Related videos on Youtube

JAL
Author by

JAL

Updated on September 18, 2022

Comments

  • JAL
    JAL 3 months

    I 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 of brew list into brew reinstall?

  • JAL
    JAL about 6 years
    I could, but then I would have to manually enter every package name from brew list. I need an automated solution that automatically pulls from brew list and reinstalls all packages.
  • JAL
    JAL about 6 years
    I had to remove a few problem formulae, but this did the trick. Thanks!
  • New Alexandria
    New Alexandria almost 4 years
    works except for casks
  • ryanjbonnell
    ryanjbonnell about 2 years
    The maintainers of HomeBrew now recommend adding --formula to only list formulae, making the updated command $ brew list --formula | xargs brew reinstall (as of November 2020).
  • Jason
    Jason almost 2 years
    Does 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.