Rails - Gem Error while installing pg (1.1.3), and Bundler cannot continue

if you're using OSX, you could try running

brew install postgresql

and then installing the gem


I had the exact same problem, and solved it by running sudo apt install postgresql-contrib libpq-dev. Then bundle worked just fine.


TL;DR; If you installed the Postgres using the PostgresAPP instead of BREW then the problem might be that you don't have the postgres bin folder in the $APTH

The solution is to find the Posgres app installation folder an in it the /bin folder.

In my case if I run which postgres doesn't work which means I don't have it in my $PATH, so what I did is I navigated to: cd /Applications/Posgres.app then to Contents and then to Versions until I found the latest folder:

/Applications/Postgres.app/Contents/Versions/latest/bin

Now, with this I can install the PG GEM by providing the path to the bin folder of my Postgres app installation

Finally, in the terminal in the root of my Rails project I ran where I provide the postgres config file path to the GEM installer:

gem install pg -v '1.2.3' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config