An error occurred while installing pg (0.17.1), and Bundler cannot continue
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:
- brew update
- brew install postgres
- gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.4/bin/pg_config
- bundle install
- 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 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
Deekor
Updated on December 13, 2020Comments
-
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 over 10 yearsIm on a mac, what should I do?
-
tungd over 10 yearsHow 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 over 10 yearsIm on a mac. I installed via the app
-
Deekor over 10 yearsI have 0.17.0 installed. Any harm in using that with rails 4?
-
tungd over 10 yearsThen try running
bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
and runbundle
again. Adjust the config path if you install the app to~/Application
rather than/Application
-
Blackcoat over 10 yearsSince 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 about 10 yearsThis was my solution (OSX)
-
Deekor about 10 yearsYup mine was in a different location as well. Thanks for the answer.
-
Deekor about 10 yearsIf this isnt working for anyone, for 9.3 the config file has moved - see the accepted answer.
-
Robertibiris about 10 yearsCorrect 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 almost 10 yearsfor me it worked with:
env ARCHFLAGS="-arch x86_64" gem install pg
-
corprew over 9 yearsAnd 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/Versions/9.4/bin/pg_config"
-
Christopher Schneider about 9 yearsFollowing the tutorial on railstutorial.org. This is what you need to do for Mint. Thanks.
-
Dennis about 9 yearsI 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 about 9 yearsIn 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/Versions/9.3/bin/pg_config
-
saiyancoder about 9 yearsIn my case (Linux Mint 17.1), install libpq-dev via apt-get made it.
-
Terra Ashley about 8 yearsrailstutorial.org -- paid tutorial; any other ideas?
-
ctlockey about 6 yearsThis worked for me while trying to
bundle install
gems included in the Ruby Getting Started Heroku walkthrough: devcenter.heroku.com/articles/… -
zykadelic almost 5 yearsYou're not installing the
pg
gem here -
theblang over 3 years@Deekor If you're using Homebrew you can run
brew install postgresql
, then thepg
gem should properly install. See these docs.