My employer gave me a MacBook Pro for development work; however, most of the development work I do in my research group is for Linux platforms, and for a host of policy reasons, I can't install virtualization software on this laptop. Homebrew looks like a good way in which to install these tools, especially because it looks very hackable (since it uses Ruby; MacPorts does not look hackable, because it uses Tcl). However, Homebrew relies on system libraries, and for security reasons, my employer may (and from what I hear, frequently will) upgrade my system at any time. I've heard that OS X upgrades will break Homebrew. (See, for instance, https://stackoverflow.com/questions/7779300/how-should-i-upgrade-xcode-after-upgrading-to-os-x-lion).


How would I go about fixing my Homebrew install after an OS X upgrade? I am fine with deleting it and starting from scratch again, as long as I can do so in an automated way. (For instance, using Puppet plus a Homebrew provider to script a configuration that will automatically build upon running a shell script.) I've been Googling everywhere and can't seem to find any answers to this question.


3 Answers 3

brew update

Updates the Homebrew installation. If there are any errors, they should be reported by brew doctor. Try fixing them else, you could use the uninstall script as follows:

# Just copy and paste the lines below (all at once, it won't work line by line!)

function abort {
  echo "$1"
  exit 1

set -e

/usr/bin/which -s git || abort "brew install git first!"
test -d /usr/local/.git || abort "brew update first!"

cd `brew --prefix`
git checkout master
git ls-files -z | pbcopy
rm -rf Cellar
bin/brew prune
pbpaste | xargs -0 rm
rm -r Library/Homebrew Library/Aliases Library/Formula Library/Contributions
test -d Library/LinkedKegs && rm -r Library/LinkedKegs
rmdir -p bin Library share/man/man1 2> /dev/null
rm -rf .git
rm -rf ~/Library/Caches/Homebrew
rm -rf ~/Library/Logs/Homebrew
rm -rf /Library/Caches/Homebrew

And install homebrew again. Am pretty sure all this is configurable using puppet.

  • 1
    I'm not sure I approve of the use of pbcopy/pbpaste as a temporary file. I hope you don't accidentally copy some text while running brew prune!
    – Quantum7
    Commented Nov 17, 2020 at 9:57

I think you might have been wondering about whether you need to rebuild all the packages rather than just uninstalling. If that is the case, I understand it is generally not a problem, as this answer says.

I've had problems, especially when changing to OS X Mavericks and Xcode 5 I had to re-link all the packages I had installed -- here's my script:

FORMULAS=(`brew list`);
for FORMULA in "${FORMULAS[@]}"
    echo "brew unlink $FORMULA" && echo "brew link $FORMULA";
    OUTPUT=`brew unlink $FORMULA`;
    echo $OUTPUT;
    OUTPUT=`brew link $FORMULA`;
    echo $OUTPUT;

Note the output, some formulas will require --force for the link step.

If that still doesn't work, try this command series from Mike McQuaid:

brew list > brew-list.txt
brew uninstall $(cat brew-list.txt)
brew install $(cat brew-list.txt)

There is now a rebuild command in HomeBrew, but that does not currently resolve dependencies.

  • 1
    I did a clean install of Mavericks on my new Mac and after that i restored a Time Machine backup from my other Mac. It left the computer with everything installed, including Homebrew and it's formulas, but all of them were unlinked. I used the script to re-link all of the formulas at once and fixed it! Works like a charm, thanks. Commented Apr 9, 2014 at 4:32
  • 1
    In a related problem I had to untap/tap all taps, otherwise brew wouldn't find some formulas even though it claimed the correct tap had already been tapped. for tap in $(brew tap); do brew untap "$tap"; brew tap "$tap"; done
    – Joel Purra
    Commented Feb 25, 2015 at 16:43

If you want to force everything to upgrade to the latest version, you need to run brew with a --greedy flag

brew upgrade --greedy

Warning : this may have undesired effects, i.e. upgrade to the next version of the app, that requires a paid upgrade. For example I had Dash.app v5., with this it upgraded me to v6, which I didn't have a license for yet.

So to see what will get upgraded, run it first with --dry-run flag

brew upgrade --greedy --dry-run

Side-effect: if you previously removed a brew-installed app through other means (not via brew) - for example, I deleted Vivaldi browser just from the Application folder, using --greedy flag may re-install it, because brew will think that you still have an older version installed. You may want to clean that up first.

  • This was asked 8 years ago, and I don't think it's relevant now since I upgraded from Mojave --> Catalina --> Big Sur without any brew packages breaking. Commented Jul 20, 2021 at 18:23
  • The reason I added the warning, was because I ran a --greedy upgrade last night, when I was looking for answers, and it updated my Dash.app to the new version, which means I had to pay for an upgrade. So both the answer and the warning are still relevant.
    – konung
    Commented Jul 21, 2021 at 17:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .