找到你要的答案

Q:Trouble installing the pg gem [duplicate]

Q:麻烦安装PG宝石[副本]

This question already has an answer here:

I've been having access denied errors when trying to run my first rails app on my mac.

When I run bundle install I get

An error occurred while installing pg (0.18.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.1'` succeeds before bundling.

Then I run gem install pg -v '0.18.1' and get the following error

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
ERROR: Failed to build gem native extension.
/Users/foo/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150502-79500-1qqztpf.rb 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.
Gem files will remain installed in /Users/foo/.rvm/gems/ruby-2.2.1/gems/pg-0.18.1 for inspection.
Results logged to /Users/foo/.rvm/gems/ruby-2.2.1/extensions/x86_64-darwin-14/2.2.0-static/pg-0.18.1/gem_make.out

这个问题在这里已经有了答案:

我一直在访问拒绝错误时,试图运行我的第一个Rails应用程序在我的Mac。

当我运行捆绑安装我得到

An error occurred while installing pg (0.18.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.1'` succeeds before bundling.

然后我运行gem install PG - V的0.18.1”得到下面的错误

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
ERROR: Failed to build gem native extension.
/Users/foo/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150502-79500-1qqztpf.rb 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.
Gem files will remain installed in /Users/foo/.rvm/gems/ruby-2.2.1/gems/pg-0.18.1 for inspection.
Results logged to /Users/foo/.rvm/gems/ruby-2.2.1/extensions/x86_64-darwin-14/2.2.0-static/pg-0.18.1/gem_make.out
answer1: 回答1:

Are you only running PostgreSQL in production? In that case make sure it is only grouped for production in your Gemfile:

group :production do 
  gem pg, '0.18.1'
end

After that, make sure to run bundle install by stating not to install production gems:

$ bundle install --without production

I hope this helps.

你是只运行PostgreSQL生产?在这种情况下,确保只有分组生产你的Gemfile:

group :production do 
  gem pg, '0.18.1'
end

在那之后,确保运行捆绑安装说明不安装生产宝石:

$ bundle install --without production

我希望这有助于。

ruby-on-rails  ruby