Installing pg gem failing on MacOS

Installing pg gem failing on MacOS

Lately, I've been hitting an error when trying to install the pg gem on my Intel MacBook. The suggestions are relatively useful. It states the following:

Unable to find PostgreSQL client library.

Please install libpq or postgresql client package like so:
  brew install libpq

or try again with:
  gem install pg -- --with-pg-config=/path/to/pg_config

or set library paths manually with:
  gem install pg -- --with-pg-include=/path/to/libpq-fe.h/ --with-pg-lib=/path/to/

After some digging, I resolved this by pointing the configuration to the specific directory. To do that, use the following command:

bundle config -- --with-pg-config=/usr/local/opt/libpq/bin/pg_config

For reference, here's the link that helped me draw my conclusion