Ruby-on-rails 无法使用 Postgres.app 在 Mavericks 中安装 pg gem

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20224483/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:04:37  来源:igfitidea点击:

Cannot install pg gem in Mavericks with Postgres.app

ruby-on-railsmacospostgresqlosx-maverickspg

提问by blundin

I am trying to install the pg gem for use with Postgres.app on my local machine. I am running Mavericks.

我正在尝试在本地机器上安装 pg gem 以与 Postgres.app 一起使用。我正在运行小牛队。

Postgres.app is installed and running fine, but I cannot get the gem to work. I've done the following:

Postgres.app 已安装并运行良好,但我无法让 gem 工作。我做了以下工作:

  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
  2. Updated Homebrew and installed the Apple GCC 4.2
  3. Installed the Xcode developer tools
  4. Updated my $PATH to reference both the Postgres.app bin and lib directories
  1. 使用 Postgres.app 文档中的命令 'env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config'
  2. 更新 Homebrew 并安装 Apple GCC 4.2
  3. 安装了 Xcode 开发者工具
  4. 更新了我的 $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!

如果您能提供任何帮助,我将不胜感激。谢谢!

回答by Tom De Leu

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_configwith:

您可以找到正确的路径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

回答by Marius Butuc

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 

回答by Louis Sayers

Being on a brand new mac, here's what I had to do:

在全新的 Mac 上,这是我必须做的:

  1. Install Xcode tools from the app store
  2. Open Xcode tools and accept the license
  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 .

  1. 从应用商店安装 Xcode 工具
  2. 打开Xcode工具并接受许可
  3. 现在运行(希望是一个面向未来的命令):

    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

回答by ylemp

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

回答by koen

adding the postgress bin dir to the path also does the trick. 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.

将 postgress bin dir 添加到路径也可以解决问题。只需像这样将 bin 添加到 pat 中即可。最近安装的最新符号链接确保此路径应该是“稳定的”,以便将来进行版本升级。

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

回答by Geoff Smith

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

Homebrew 可以在这里找到

http://brew.sh

http://brew.sh

回答by Gabriel Osorio

For future reference, since a lot of us are posting new paths for the new version numbers:

为了将来参考,因为我们很多人都在发布新版本号的新路径:

Currently I'm seeing a symlink called latestin /Applications/Postgres.app/Contents/Versions/.

目前我看到一个叫符号链接latest/Applications/Postgres.app/Contents/Versions/

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.

忘记版本号。这可能不适用于每个(旧)版本,但我自己正在寻找可以保存和重用的片段。

回答by Gerry

This worked for me:

这对我有用:

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