In this guide, I wanna walk through a common error that I’ve seen quite a few students and developers run into when they’re setting up their configuration for Postgres and connecting that to Rails.
This is in reference to a student question where the student said that they got an error that says Gem Extension Build ERROR: Failed to build gem native extension. This can be a confusing error message. The key here that you want to look at is where it says to to add the pg_config path to the gem install pg command.
Now that’s nice because that typically is the fix, but if you’re relatively new to development especially to the terminal and the command line system, then that might be kind of confusing. You may not know where exactly to find that and so that’s what I wanna show you in this guide, and then we can run this entire gem command.
To find out where Postgres is installed, you can run this command:
And it will output the entire path to Postgres. And this is exactly what we’re looking for. And this will work whether you have Postgres installed via homebrew or the Postgres App, when I run the command on my system, it outputs:
If you run the command:
You will see that the bin/ directory contains the pg_config file that we’ll need to pass to the ‘gem install pg’ command.
So now you can run a command with the path to your pg_config file, for my system and version of Postgres, the full command is:
gem install pg — –with-pg-config=/Applications/Postgres.app/Contents/Versions/11/bin/pg_config