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

86,464

Solution 1

I'm on a Mac running Mavericks. My solution was to install Postgres.

And then in terminal install 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 edited to use the latest symlink that is currently included in shipping versions of the Postgres app.

Previous versions suggested:

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

Solution 2

Some kind of error resported here Installing PG gem on OS X - failure to build native extension

To install dependencies on Ubuntu try this:

sudo apt-get install libpq-dev

and this

gem install pg

Solution 3

app root:

  1. brew update
  2. brew install postgres
  3. gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.4/bin/pg_config
  4. bundle install
  5. ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
  6. launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
  7. createuser -s -r postgres
  8. rake db:create:all
  9. rake db:migrate
  10. rails s

NOTE: replace the version number in step 3 if needed.

Solution 4

Previously working answer with older version

I installed under mac OSX Mavericks, having the postgres app (Version 9.2.2.0 ) from www.postgresapp.com installed. The underlying problem was simpy that the since postgres was installed via the app, the configuration file resides on a location which is not the default one when installing it without postgressapp. so we need to tell gem where to find this file by:

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

Hope it helps

Solution 5

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 the PostgreSQL.app Documentation

Share:
86,464
Deekor
Author by

Deekor

Updated on December 13, 2020

Comments

  • Deekor
    Deekor over 3 years

    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?

  • Deekor
    Deekor over 10 years
    Im on a mac, what should I do?
  • tungd
    tungd over 10 years
    How about your Ruby/Bundler setup? You're using Mac OS X or Linux? and if you're using Mac OS X, you installed PostgreSQL via homebrew or PostgreSQL.app?
  • Deekor
    Deekor over 10 years
    Im on a mac. I installed via the app
  • Deekor
    Deekor over 10 years
    I have 0.17.0 installed. Any harm in using that with rails 4?
  • tungd
    tungd over 10 years
    Then try running bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/MacOS/b‌​in/pg_config and run bundle again. Adjust the config path if you install the app to ~/Application rather than /Application
  • Blackcoat
    Blackcoat over 10 years
    Since the official app recently changed names to "Postgres93.app", the command should be: env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS‌​/bin/pg_config
  • raulriera
    raulriera about 10 years
    This was my solution (OSX)
  • Deekor
    Deekor about 10 years
    Yup mine was in a different location as well. Thanks for the answer.
  • Deekor
    Deekor about 10 years
    If this isnt working for anyone, for 9.3 the config file has moved - see the accepted answer.
  • Robertibiris
    Robertibiris about 10 years
    Correct Bob, the version of postgresapp in which this worked for me, was Version 9.2.2.0, so they must have changed this location on the 9.3 release.
  • dnlcrl
    dnlcrl almost 10 years
    for me it worked with: env ARCHFLAGS="-arch x86_64" gem install pg
  • corprew
    corprew over 9 years
    And now, as of 1/22/15 we're looking at the 9.4 release, it's good to see they're keeping it updated -- "gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Version‌​s/9.4/bin/pg_config"
  • Christopher Schneider
    Christopher Schneider about 9 years
    Following the tutorial on railstutorial.org. This is what you need to do for Mint. Thanks.
  • Dennis
    Dennis about 9 years
    I was in a rush and missed the part of this answer that says "install using home-brew". This answer worked for me after I did brew update; brew install postgres
  • user1322092
    user1322092 about 9 years
    In your solution, please add the version, other the latest PG gem will install: gem install pg -v '0.17.1' -- --with-pg-config=/Applications/Postgres.app/Contents/Version‌​s/9.3/bin/pg_config
  • saiyancoder
    saiyancoder about 9 years
    In my case (Linux Mint 17.1), install libpq-dev via apt-get made it.
  • Terra Ashley
    Terra Ashley about 8 years
    railstutorial.org -- paid tutorial; any other ideas?
  • ctlockey
    ctlockey about 6 years
    This worked for me while trying to bundle install gems included in the Ruby Getting Started Heroku walkthrough: devcenter.heroku.com/articles/…
  • zykadelic
    zykadelic almost 5 years
    You're not installing the pg gem here
  • theblang
    theblang over 3 years
    @Deekor If you're using Homebrew you can run brew install postgresql, then the pg gem should properly install. See these docs.