安装pg(0.17.1)时发生错误,Bundler无法继续

Dee*_*kor 83 postgresql macos ruby-on-rails ruby-on-rails-4

我刚刚安装Rails 4.0.2并在创建新应用时,在捆绑阶段我得到:

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.
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

Tal*_*kov 166

在此处报告了某种错误在OS X上安装PG gem - 无法构建本机扩展

要在Ubuntu上安装依赖项,请尝试以下操作:

sudo apt-get install libpq-dev
Run Code Online (Sandbox Code Playgroud)

还有这个

gem install pg
Run Code Online (Sandbox Code Playgroud)

  • 我在Mac上,我该怎么办? (5认同)

小智 136

我正在Mac上运行小牛队.我的解决方案是安装Postgres.

然后在终端安装中使用自制的配置:

gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
Run Code Online (Sandbox Code Playgroud)

注意:此答案已经过编辑,以使用latest当前包含在Postgres应用程序的发布版本中的符号链接.

以前的版本建议:

gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
Run Code Online (Sandbox Code Playgroud)

  • 在你的解决方案中,请添加版本,其他最新的PG gem将安装:`gem install pg -v'0.17.1' - --with-pg-config =/Applications/Postgres.app/Contents/Versions/9.3 /斌/ pg_config` (6认同)
  • 我匆匆忙忙地错过了这个答案的一部分,上面写着"使用家庭酿造安装".在我做了"brew update"之后,这个答案对我有用了.brew安装postgres` (2认同)

kni*_*ice 19

app root:

  1. brew更新
  2. brew安装postgres
  3. gem install pg - --with-pg-config =/usr/local/Cellar/postgresql/9.3.4/bin/pg_config
  4. 捆绑安装
  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. 导轨

注意:如果需要,请替换步骤3中的版本号.


Rob*_*ris 11

以前使用旧版本的工作答案

我安装了Mac OSX Mavericks,安装了www.postgresapp.com的postgres应用程序(版本9.2.2.0).根本问题是,自从postgres通过应用程序安装后,配置文件驻留在一个位置,这个位置在没有postgressapp的情况下安装时不是默认位置.所以我们需要告诉gem在哪里找到这个文件:

gem install pg - --with-pg-config =/Applications/Postgres.app/Contents/MacOS/bin/pg_config

希望能帮助到你


Vin*_*nce 5

如果gem install pg失败,请尝试以下命令:

env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
Run Code Online (Sandbox Code Playgroud)

...来自PostgreSQL.app文档

  • 由于官方应用程序最近将名称更改为"Postgres93.app",命令应为:`env ARCHFLAGS =" - arch x86_64"gem install pg - --with-pg-config =/Applications/Postgres93.app/Contents/MacOS的/ bin中/ pg_config` (2认同)