The standard instruction for installing the postgres gem on MacOS is to install the entire Postgres app by entering

brew install postgres

I wanted to do a leaner install and after digging through some StackOverflow articles, I found that you could just install the Postgres libraries by entering

brew install libpq

However, what tends to happen is that it runs into other issues. The constant error I get is

checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:

To get around this issue, you have to specify some build commands for your mac

bundle config --local --with-opt-dir="/usr/local/opt/libpq"

Install pg gem fails on MacOS