Rebuilding installed formulae #11833

Mochaleaf opened this Issue Apr 23, 2012 · 17 comments


None yet

10 participants


This is a feature request.

It would be nice if you could re-compile all of the formulae on your system. I just upgraded to Mountain Lion Seed 3, and some of the system libraries have changed (which means, I need to recompile the formulae that were built against older libraries).


FORMULAE=brew list; echo brew uninstall $FORMULAE; echo brew install $FORMULAE

I don't think this is a common enough usecase to implement it more than this, sorry.

gnzlbg commented Nov 28, 2012

Your approach is valid as long as you are not passing any options. When Apple updates the compilers I like to reinstall everything. My script is not so simple because of the install options... I would find such a feature useful.

rburhum commented Sep 25, 2013



@rburhum This is a year-old closed issue. In the meantime we've added a brew reinstall command that does respect options.

rburhum commented Sep 25, 2013

I was looking through the documentation looking for exactly that @mistydemeo . Thank you!

natevw commented Oct 23, 2013

I just upgraded from Lion (10.7) to Mavvrx (10.9) and this would definitely come in handy as some items no longer work as originally compiled. As soon as Xcode 5.0.1 finishes installing I'm going to try brew list | xargs brew reinstall which in theory will rebuild everything. I'll post back/edit if not.

natevw commented Oct 23, 2013

Simply reinstalling the full list didn't work because it doesn't resolve dependencies in order. I.e. "ab" won't reinstall until "apr" is reinstalled but it gets listed first. Guess I may just uninstall everything and reinstall various deps as I need them again…

brew list > brew-list
brew uninstall `cat brew-list`
brew install `cat brew-list`
rburhum commented Oct 24, 2013

@mikemcquaid this will not take in consideration all the install flags that are very important for several of my dependent projects

brew reinstall `brew list`

may work for you. If not we'll welcome patches to improve it.

rburhum commented Oct 24, 2013

Will try. I have done contributions of recipes in the past. Nevertheless, I am not a Ruby developer, but if your suggestion doesn't work I can try to see if I can hack something. Thanks @mikemcquaid


I wasn't a Ruby developer and now I'm one of the Homebrew maintainers and write Ruby for a living. We'll help you out, don't worry.

rex commented Nov 20, 2013

I apologize if I am intruding on this issue, but I wanted to leave something for any junior or hobbyist developers that find this in the future.

@mikemcquaid's point is extremely good developer-life advice. Very frequently, the best way to teach yourself a new language is by finding a reason to learn it and then just doing it. You'll end up creating the thing that you needed in the first place and who knows, maybe you'll learn how to write code in that language along the way.


@rex 😊


If brew reinstall actually rebuilds the packages (for me, that's not what it looks like), then we could use:

  • brew list to get all packages;
  • brew deps to get dependencies per package;
  • tsort to get an installation order where every package is installed only after all its dependencies are installed;
  • brew reinstall to reinstall each package in the correct order.
#!/usr/bin/env bash

# Notes: 
#  - tsort requires as input a stream of pairs (a, b) where package a depends
#    on package b. If package a has k > 1 dependencies, we should have k lines
#    associated to it; if package a has no dependencies, then we should have a
#    single line (a, a). The pairs are just space delimited, no parentheses.
#    the little awk program below formats the data that way for tsort.
#  - tsort outputs the order from bottom to top; that's why we need to reverse
#    it with tail -r.

brew list \
  | while read l; do echo -n "$l "; echo $(brew deps $l); done \
  | awk 'NF == 1 {print $1, $1} NF > 1 {for (i=1;i<=NF;i++) print $1, $i}' \
  | tsort \
  | tail -r \
  | while read l; do echo -n "$l "; brew reinstall $l; done

In my tests, it doesn't look like anything was recompiled. So I'll try "uninstall... install" instead of "reinstal".


Is "brew reinstall" still a valid thing? It is not listed on

I found this (long closed) issue while trying to figure out how to rebuild a formula because I discovered after the fact that I should have included an option (did "brew install opencv" should have done "brew install opencv --with-java --with-qt").


@gpfreitas Nice one, I used your script it with a couple of changes,

  1. I couldn't use -r for tail (found out it is a bsd only feature) so I used tac which is the opposite of cat and is included in coreutils
  2. I added -v to the arguments of brew reinstall and saw that many packages got recompiled.
@xu-cheng xu-cheng locked and limited conversation to collaborators Feb 16, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.