Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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

share|improve this question
add comment

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

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

2 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
    
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 Iglesias Apr 9 at 4:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.