Reviewing Caveats of Homebrew packages

Have you ran into problems after Homebrew upgrade?

If you are a Homebrew user on Mac OS X, you might have faced problems after starting a Homebrew upgrade.

If you could review the upgrade log, you might find what went wrong and which configuration and commands you still need to do to get everything working again.

But what if you could not review the brew upgrade log? disaster?

No… Brew keeps these installation information and instructions in a section called Caveats in each of the installed packages… So the solution here is to look for the Caveat section in the info of each of the installed packages using brew info like this:

$ brew info postgresql
 postgresql: stable 12.1 (bottled), HEAD
 Object-relational database system
 https://www.postgresql.org/
 /usr/local/Cellar/postgresql/12.1 (3,217 files, 37.7MB) *
   Poured from bottle on 2019-11-24 at 19:48:53
 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/postgresql.rb
 ==> Dependencies
 Build: pkg-config ✔
 Required: icu4c ✔, krb5 ✘, openssl@1.1 ✔, readline ✔
 ==> Options
 --HEAD
 Install HEAD version
 ==> Caveats
 To migrate existing data from a previous major version of PostgreSQL run:
   brew postgresql-upgrade-database
 

 To have launchd start postgresql now and restart at login:
   brew services start postgresql
 Or, if you don't want/need a background service you can just run:
   pg_ctl -D /usr/local/var/postgres start
 ==> Analytics
 install: 63,955 (30 days), 214,120 (90 days), 996,250 (365 days)
 install-on-request: 59,182 (30 days), 197,774 (90 days), 913,033 (365 days)
 build-error: 0 (30 days) 

The Caveat section marked by ==> Caveats contains the information that you are seeking.

Repeating that for all installed packages will take a lot of manual unnecessary work, and you will have to look at tons of text that is not relevant to your use case.

This bash command mentioned on this thread on stackoverflow.com. helps:

$ brew info postgresql | sed '/==> Caveats/,/==>/!d;//d'
brew info postgresql | sed '/==> Caveats/,/==>/!d;//d'
To migrate existing data from a previous major version of PostgreSQL run:
  brew postgresql-upgrade-database

To have launchd start postgresql now and restart at login:
  brew services start postgresql
Or, if you don't want/need a background service you can just run:
  pg_ctl -D /usr/local/var/postgres start

It simply takes the output of brew info postgresql and then looks for the ==> Caveat using the sed command, truncating all unnecessary additional information.

Now if we combine it with the command brew list to retrieve the list of packages and passed the result to brew info like this:

$ brew info $(brew list) | sed '/==> Caveats/,/==>/!d;//d'

Will output all caveat sections of all installed packages if the caveat section existed.

Rafael Garrido created this external brew command to integrate this functionality into homebrew. You can find the source code on github under: https://github.com/rafaelgarrido/homebrew-caveats

To install the tool, either install manually or use brew to tap into the repository using the following commands:

$ brew tap rafaelgarrido/homebrew-caveats 

Then the following command to install the homebrew-caveats package

$ brew install homebrew-caveats

Now you can use the tool like this:

$ brew caveats postgresql

That’s it. I hope this short How-To guide help.

Happy fixing.