Reinstall All Homebrew Packages

After upgrading to OS X Sierra I was unable to start MariaDB (or MySQL). Long story short, I ended up rebuilding openssl which fixed the signal 4 error, likely due to changes in the compiler. I decided that recompiling all the packages would be a good idea to prevent any future issues, and after some digging found this script which I modifying slightly.


# Reinstall all brew packages and dependencies in the correct order 
# - list all installed packages
# - print the package followed by its dependencies
# - print the package and a single depenency on each line
# - perform a topographical sort
# - use tail to reverse the order
# - print out each package in the correct order on a single line
# - pass to brew reinstall
brew list \
  | while read package; do echo -n "$package "; echo $(brew deps $package); done \
  | awk 'NF == 1 {print $1, $1} NF > 1 {for (dep=1; dep<=NF; dep++) print $1, $dep}' \
  | tsort \
  | tail -r \
  | REINSTALL_LIST=$(while read package; do echo -n "$package "; done) \
  | brew reinstall $REINSTALL_LIST

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *