Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 693
Deekor Avatar asked Dec 24 '13 02:12

Deekor


4 Answers

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
like image 109
Talgat Medetbekov Avatar answered Nov 17 '22 11:11

Talgat Medetbekov


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
like image 38
Bob O'Brien Avatar answered Nov 17 '22 10:11

Bob O'Brien


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.

like image 23
knice Avatar answered Nov 17 '22 11:11

knice


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

like image 11
Robertibiris Avatar answered Nov 17 '22 10:11

Robertibiris