What's the best way to update Homebrew when upgrading macOS?

Solution 1:

Homebrew manages all updating/upgrading by itself. Run brew update && brew upgrade every once in a while (and you can do it after upgrading macOS). brew update will update the list of available formulae, and brew upgrade will upgrade any outdated packages.

If you like, everything can be scripted as well:

  1. Run the macOS installer: startosinstall
  2. Run all macOS updates for Xcode, etc..: softwareupdate -ai
  3. Update homebrew itself and the package lists: brew update
  4. Upgrade all software installed with homebrew: brew upgrade
  5. Upgrade all casks installed with homebrew: brew upgrade --cask
  6. Remove old versions of installed software: brew cleanup

You don't need to remove/uninstall anything before upgrading macOS. Just download the macOS installer from the App Store (or from System Preferences), and follow the instructions to install the new OS like normal.