25

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.

migrated from stackoverflow.com Mar 14 '13 at 20:17

This question came from our site for professional and enthusiast programmers.

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

7

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.

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

You must log in to answer this question.

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