If you have installed Posgres on a Mac using the Postgres App. This guide walks through how to fix the pg gem install error that says:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
We'll walk through how to find the version of postgres installed on your machine along with the pg_config file. We'll also run the gem install pg command with the pg_config path flag.
An example install command (for my personal machine and version) is:
gem install pg -v '1.2.3' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/12/bin/pg_config