An error occurred while installing pg (0.17.1), and Bundler cannot continue

Viewed 87975

I just installed Rails 4.0.2 and when creating a new app, in the bundle stage I get:

Installing pg (0.17.1) 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/Dee/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb 
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
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.

How do I fix this?

17 Answers

For CentOS users:

sudo yum install postgresql-devel

and

gem install pg

I have just set up a new Macbook Pro which was prebuilt with Catalina.

What worked for me:

  1. Install the Postgres from here: https://postgresapp.com/
  2. Add export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"to your .zshenv, since Z shell is now the default terminal.

I was having a problem with Amazon and couldn't use apt-get. For my worked:

    sudo yum install postgresql-devel

then:

    bundle install

and try again:

    rails serve

If you installed through Homebrew; gem install pg -- --with-pg-config=/usr/local/bin/pg_config. Works with Ruby 2.4.6 and pg 0.20.0.

On mac this command worked for me.

gem install pg -v '0.18.4' -- --with-cflags="-Wno-error=implicit-function-declaration"

It works for me

rvm list gemsets
rvm use ruby-2.4.1
bundle

error[![resolved with rvm use ruby]2

Related