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.

I just upgraded my MacBook Air to Mavericks. The process appears to have removed almost all of the symlinks that homebrew put in /usr/local/bin. As I notice things missing then I relink them via brew unlink <keg> && brew link <keg> (although the symlinks are gone, homebrew still thinks they are there so I need to unlink first). This feels somewhat inefficient.

I could just loop through everything in /usr/local/Cellar but not every keg is automatically linked and I don't want to link those. So my next guess is to list every linked keg and relink them (using the above).

Is there some magic command that will find all the kegs that homebrew thinks are linked so that I can relink them?

share|improve this question
    
I used Migration Assistant to move "everything" from an old Mac to a new one, and I also lost all my homebrew symlinks. Annoying. –  Grav Mar 30 at 13:31

3 Answers 3

up vote 17 down vote accepted

/usr/local/Library/LinkedKegs seems to contain a list of, well, linked kegs, so this should do the trick:

ls -1 /usr/local/Library/LinkedKegs | while read line; do
    echo $line
    brew unlink $line
    brew link --force $line
done

I'd recommend ensuring you have write permissions to /usr/local/lib again before trying this.

share|improve this answer
    
Pretty sure that this just restored my homebrew into working order. Thanks! –  Robert Massaioli Jul 15 at 6:43

This bash command (taken from there) it will unlink all installed formulas and link them again:

brew list -1 | while read line; do brew unlink $line; brew link $line; done

I guess that all formulas needed to be linked, otherwise whichever tool is depended on them would have troubles finding them.

share|improve this answer
    
I'm not sure that all formulae do need to be linked. Some are keg-only but I don't know which, since some were installed as dependencies of others. –  Loop Space Mar 11 at 21:31
3  
It seems you just get some warnings like "Warning: extempore is keg-only and must be linked with --force" –  Grav Mar 30 at 13:29
    
Here's an equivalent version using xargs: brew list -1 | xargs -I formula sh -c "brew unlink formula && brew link formula" –  noa Apr 19 at 23:54

In addition to the other answers to this question, you may also need to relink formula with multiple versions installed (brew link won't do this for you).

First, relink all the formulas you can:

brew list -1 | while read line; do brew unlink $line; brew link --force $line; done

Then run brew doctor, which should complain and give you two lists:

  • Unlinked formulae with multiple versions
  • Keg-only formulae which have been incorrectly link by the original relinking process.

For each formula with multiple versions run the following, replacing "python" with the formula name:

brew info python  

This will show you, among other information, all installed versions. Choose which version you want to link (for me its 2.7.6), and use brew switch

brew switch python 2.7.6

You will also want to run brew unlink on the list (if any) of keg-only formulae that have been linked.

share|improve this answer

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.