# How should I fix my Homebrew installation after upgrading OS X?

## Context

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).

## Question

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.

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:

#!/bin/sh
# Just copy and paste the lines below (all at once, it won't work line by line!)
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY!

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. • 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 Nov 17 '20 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: #!/bin/bash FORMULAS=(brew list); for FORMULA in "${FORMULAS[@]}"
do
echo "brew unlink $FORMULA" && echo "brew link$FORMULA";
OUTPUT=brew unlink $FORMULA; echo$OUTPUT;
OUTPUT=brew link $FORMULA; echo$OUTPUT;
done


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.

• 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. – Alejandro García Iglesias Apr 9 '14 at 4:32
• 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 Feb 25 '15 at 16:43