gem 安装 postgre 错误 - Mac 10.10

gem install postgre error - Mac 10.10

大家好,我正在尝试在我的 macOS 上安装 postgre:Yosemite 10.10.2

首先,我这样做是因为我试图在不支持 sqlite 的 Heroku 上部署我的应用程序,所以我做了以下操作:

group :development, :test do
  gem 'sqlite3'
  gem 'sqlite3-ruby', :require => 'sqlite3'
end

group :production do
  gem 'pg'
end

所以当我在 heroku 上部署它时它工作正常。

但现在我不能再 运行 'bundle install' 因为它说 我使用了命令:

sudo gem install pg --
--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
--with-pg-include='/Applications/Postgres.app/Contents/Versions/9.3/include/'
-–with-pg-lib=/usr/lib

(我之前也分别试过每一个)

这是我得到的:

sudo gem install pg -- 
--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config  
--with-pg-include='/Applications/Postgres.app/Contents/Versions/9.3/include/' 
–with-pg-lib=/usr/lib
Building native extensions with: '--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config --with-pg-include=/Applications/Postgres.app/Contents/Versions/9.3/include/ –with-pg-lib=/usr/lib'
This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20150208-28855-hgneo3.rb extconf.rb --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config --with-pg-include=/Applications/Postgres.app/Contents/Versions/9.3/include/ –with-pg-lib=/usr/lib
Using config values from /Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)

*** 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.
   extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/pg-0.18.1 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14/2.0.0/pg-0.18.1/gem_make.out

我不明白为什么他不能得到 PQconnectdb() ? 我在这里遗漏了什么吗?

提前致谢=)

虽然你在本地电脑上基本不用"production"环境,但是你还是需要在你的电脑上安装postgres才能正常使用。根据您的日志,您似乎没有正确安装 postgres。

我推荐使用homebrew安装:

brew install postgres

在通过自制软件安装 postgres 后安装 pg gem 时不应出现此错误。

如果您使用其他方法安装它,您可能需要在安装 pg gem 时添加一些参数。以下是一些参考资料:

Installing PostgreSQL gem under Ubuntu and Mac

Can't find the PostgreSQL client library (libpq)