简体   繁体   English

无法使用Postgres.app在小牛中安装pg gem

[英]Cannot install pg gem in Mavericks with Postgres.app

I am trying to install the pg gem for use with Postgres.app on my local machine. 我正在尝试在本地计算机上安装pg gem与Postgres.app一起使用。 I am running Mavericks. 我在跑小牛。

Postgres.app is installed and running fine, but I cannot get the gem to work. Postgres.app已安装并运行良好,但是我无法运行该gem。 I've done the following: 我已经完成以下工作:

  1. Used the command 'env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config' from the Postgres.app documentation 使用了来自Postgres.app文档的命令'env ARCHFLAGS =“-arch x86_64” gem install pg---with-pg-config = / Applications / Postgres.app / Contents / MacOS / bin / pg_config
  2. Updated Homebrew and installed the Apple GCC 4.2 更新了Homebrew并安装了Apple GCC 4.2
  3. Installed the Xcode developer tools 安装了Xcode开发人员工具
  4. Updated my $PATH to reference both the Postgres.app bin and lib directories 更新了我的$ PATH以同时引用Postgres.app bin和lib目录

All with no success. 一切都没有成功。 Here is the specific error message I receive: 这是我收到的特定错误消息:

Building native extensions with: '--with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config'
This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    /Users/Brian/.rvm/rubies/ruby-2.0.0-p353/bin/ruby extconf.rb --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
Using config values from /Applications/Postgres.app/Contents/MacOS/bin/pg_config
sh: /Applications/Postgres.app/Contents/MacOS/bin/pg_config: No such file or directory
sh: /Applications/Postgres.app/Contents/MacOS/bin/pg_config: No such file or directory
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.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/Brian/.rvm/rubies/ruby-2.0.0-p353/bin/ruby
    --with-pg
    --without-pg
    --with-pg-config
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/

I'd appreciate any help you can offer. 我会很感激您能提供的任何帮助。 Thanks! 谢谢!

You probably have the wrong path for --with-pg-config , check if it's actually there. 您可能使用--with-pg-config路径错误,请检查它是否确实存在。

You can find the correct path to pg_config with: 您可以使用以下命令找到pg_config的正确路径:

find /Applications -name pg_config

In the latest Postgres.app Version the path is: 在最新的Postgres.app版本中,路径为:

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

In my case (running Postgres.app v9.3.4.2) it only seemed to work when prepending the environment architecture flags: 就我而言(运行Postgres.app v9.3.4.2),它似乎仅在附加环境体系结构标志时才起作用:

env ARCHFLAGS="-arch x86_64" gem install pg -- \
--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config 

Being on a brand new mac, here's what I had to do: 在全新的Mac上,这是我要做的事情:

  1. Install Xcode tools from the app store 从应用商店安装Xcode工具
  2. Open Xcode tools and accept the license 打开Xcode工具并接受许可
  3. Now run (hopefully a future-proofed command): 现在运行(希望是一个经过验证的命令):

    version=$(ls /Applications/Postgres.app/Contents/Versions/ | tail -1) gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/$version/bin/pg_config .

If you have trouble, you can troubleshoot a bit by checking out the actual error in the mkmf.log which you can find by running (if using rvm): 如果遇到问题,可以通过检查mkmf.log中的实际错误(通过运行(如果使用rvm)可以找到)发现一些故障:

cd ~/.rvm ; find . -name mkmf.log | grep pg

I was able to install pg with this command 我能够使用此命令安装pg

    gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config

I found my path by running 我通过跑步找到了自己的路

    sudo find / -name "pg_config"

and I Successfully installed pg-0.17.1 并且我成功安装了pg-0.17.1

adding the postgress bin dir to the path also does the trick. 将postgress bin目录添加到路径也可以解决问题。 just add the bin to the pat like this. 像这样将垃圾箱添加到拍拍中 with recent installs the latest symbolic link makes sure that this path should be 'stable' for future version upgrades. 对于最新安装的产品,最新的符号链接可确保此路径在以后的版本升级中应该是“稳定的”。

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin

To resolve this issue I installed postgres using homebrew using the following in the terminal window: 要解决此问题,我在终端窗口中使用以下方法使用自制软件安装了postgres:

brew install postgres

Homebrew can be found here 自制酒可以在这里找到

http://brew.sh http://brew.sh

这对我有用:

gem install pg -- --with-pg-config=`which pg_config`

For future reference, since a lot of us are posting new paths for the new version numbers: 供以后参考,因为我们很多人都在发布新版本号的新路径:

Currently I'm seeing a symlink called latest in /Applications/Postgres.app/Contents/Versions/ . 目前,我在/Applications/Postgres.app/Contents/Versions/看到一个名为latest的符号链接。

You should be able to just do: 您应该能够做到:

$ gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config

And forget about the version number. 忘记版本号。 This might not apply to every (older) version, but I myself was looking for a snippet I could save and reuse. 这可能不适用于每个(较旧的)版本,但我本人正在寻找可以保存和重复使用的代码段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM