Error installing pg (0.17.1) and Bundler cannot continue

I just installed Rails 4.0.2 , and when I create a new application at the package 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 to fix it?

+80
ruby-on-rails postgresql ruby-on-rails-4 macos
Dec 24 '13 at 2:28
source share
15 answers

I am on a Mac with Mavericks. My solution was to install Postgres .

And then in a terminal installation using homebrew with the configuration:

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

Note. This answer has been modified to use the latest symlink, which is currently included in the delivery version of the Postgres application.

Previous Versions:

 gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config 
+133
Mar 19 '14 at 1:43
source share

Some mistake shifted here Installing the PG pearl on OS X - the inability to create your own extension

To install dependencies on Ubuntu, try the following:

 sudo apt-get install libpq-dev 

and this one

 gem install pg 
+154
Dec 24 '13 at 2:42 on
source share

root applications:

  • brew update
  • brew install postgres
  • gem install pg - --with-pg-config = / usr / local / Cellar / postgresql / 9.3.4 / bin / pg_config
  • install package
  • ln -sfv / usr / local / opt / postgresql / *. plist ~ / Library / LaunchAgents
  • launchctl load ~ / Library / LaunchAgents / homebrew.mxcl.postgresql.plist
  • createuser -s -r postgres
  • rake db: create: all
  • rake db: migrate
  • rails s

NOTE. Replace the version number in step 3 if necessary.

+18
May 7 '14 at 21:12
source share

Previously working answer with the old version

I installed Mavericks under Mac OSX by installing the postgres application (Version 9.2.2.0) from www.postgresapp.com . The main problem was that since postgres was installed through the application, the configuration file is in a location that is not the default directory when it is installed without postgressapp. so we need to tell gem where to find this file:

 gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config 

Hope help

+11
Feb 05 '14 at 10:34
source share

If gem install pg fails, try the following command:

 env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config 

... from PostgreSQL.app Documentation

+5
Dec 24 '13 at 2:57
source share

It looks like you do not have PostgreSQL. pg graphics require some PostgreSQL headers to build their own extension.

+4
Dec 24 '13 at 2:38
source share

I had to combine everything and use

 sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config 
+3
Apr 28 '15 at 16:28
source share

If you use something other than Postgres in development and Postgres only in production, you can add pg gem to your gemfile, for example ...

 group :production do gem 'pg', '0.17.1' end 

Then use bundle install --without production

+2
Aug 14 '15 at 5:12
source share

For CentOS users:

 sudo yum install postgresql-devel 

and

 gem install pg 
+2
Oct 19 '17 at 5:47 on
source share

After installing Postgres, I had to run the following command

 env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config 

After installing this build works great!

Hope this helps

0
Nov 02 '14 at 1:26
source share

How I managed to get past this error:

  • cd to the application folder, and then install the ruby โ€‹โ€‹version locally. I am using ruby โ€‹โ€‹2.1.2.

rbenv local 2.1.2

  • instead of just installing the package, install the gems in the supplier / kit

bundle install --path vendor / bundle

It did it for me.

0
Nov 18 '14 at 15:36
source share

I needed to use sudo

 sudo gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.5/bin/pg_config 
0
Feb 29 '16 at 0:18
source share

I had problems with Amazon and I could not use apt-get. For my work:

  sudo yum install postgresql-devel 

then:

  bundle install 

and try again:

  rails serve 
0
Apr 01 '19 at 22:40
source share

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

0
May 14 '19 at 16:36
source share

It works for me

 rvm list gemsets rvm use ruby-2.4.1 bundle 

error [! [resolved with rvm use ruby ] 2

-2
Jan 27 '18 at 23:13
source share



All Articles