An error occurred while installing pg (0.17.1), an

2019-01-08 06:32发布

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?

13条回答
你好瞎i
2楼-- · 2019-01-08 06:48

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
查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-01-08 06:49

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
查看更多
【Aperson】
4楼-- · 2019-01-08 06:50

For CentOS users:

sudo yum install postgresql-devel

and

gem install pg
查看更多
beautiful°
5楼-- · 2019-01-08 06:52

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

查看更多
走好不送
6楼-- · 2019-01-08 06:52

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 this bundle install works great!

Hope it helps

查看更多
狗以群分
7楼-- · 2019-01-08 06:56

If you are using something other than Postgres in development and Postgres in production only, you can add the pg gem to your gemfile like so...

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

Then use bundle install --without production

查看更多
登录 后发表回答