Ruby-on-rails 在 OS X 上安装 PG gem - 无法构建本机扩展

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19262312/
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 22:50:33  来源:igfitidea点击:

Installing PG gem on OS X - failure to build native extension

ruby-on-railsmacospostgresqlgem

提问by Mel

It seems many others have had problems installing the pg gem. None of the solutions posed for others have worked for me.

似乎许多其他人在安装 pg gem 时遇到了问题。为其他人提出的解决方案都没有对我来说有效。

I have tried to install the pg gem and postgres.app. The pg gem won't install. The first error I get is:

我尝试安装 pg gem 和 postgres.app。pg gem 不会安装。我得到的第一个错误是:

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

安装 pg (0.17.0) 时出错,Bundler 无法继续。gem install pg -v '0.17.0'在捆绑之前确保成功。

The installation advice about pointing my gem install to the config for pg fails with the following error message (which many others on this forum have encountered):

关于将我的 gem install 指向 pg 配置的安装建议失败,并显示以下错误消息(本论坛上的许多其他人都遇到过):

Failed to build native extensions... Results logged to /Users/melanie/.rvm/gems/ruby-1.9.3-p448/gems/pg-0.17.0/ext/gem_make.out

I don't know how to find or access this log file to search for further clues.

我不知道如何查找或访问此日志文件以搜索更多线索。

I also get an error message (command not found) when I try using the sudo apt-get install command. I've scoured this forum for the last 6 hours, trying each piece of advice to get pg working with my rails project.

当我尝试使用 sudo apt-get install 命令时,我也收到一条错误消息(未找到命令)。在过去的 6 个小时里,我已经浏览了这个论坛,尝试了每一条建议来让 pg 与我的 rails 项目一起工作。

I can't find advice about how to change a path, or specifically, what change is required. My which pg_configreturns a file source. I've used that with a command to install pg using that config. It fails.

我找不到有关如何更改路径的建议,或者具体来说,需要进行哪些更改。我的which pg_config返回一个文件源。我已经将它与命令一起使用,以使用该配置安装 pg。它失败。

There are so many people that have had trouble with this. Many answers suggest homebrew. I've had to remove that because it threw up other issues.

有很多人遇到过这个问题。许多答案都建议自制。我不得不删除它,因为它引发了其他问题。

回答by shicholas

Same error for me and I didn't experience it until I downloaded OS X 10.9 (Mavericks). Sigh, another OS upgrade headache.

我也遇到了同样的错误,直到我下载了 OS X 10.9 (Mavericks) 才遇到它。唉,又是一个操作系统升级头疼的问题。

Here's how I fixed it (with homebrew):

这是我修复它的方法(使用自制软件):

  • Install another build of Xcode Tools (typing brew updatein the terminal will prompt you to update the Xcode build tools)
  • brew update
  • brew install postgresql
  • 安装另一个构建的 Xcode Tools(brew update在终端中输入将提示您更新 Xcode 构建工具)
  • brew update
  • brew install postgresql

After that gem install pgworked for me.

之后gem install pg对我来说有效。

回答by sandesh kota

If you are using Ubuntu try to install following lib file

如果您使用的是 Ubuntu,请尝试安装以下 lib 文件

sudo apt-get install libpq-dev

and then

进而

gem install pg

gem install pg

worked for me.

对我来说有效。

回答by Jon

I am using OS X Mavericks (version 10.9)

我正在使用 OS X Mavericks(版本 10.9)

and when I run the above I got the following message: If builds of PostgreSQL 9 are failing and you have version 8.x installed.

当我运行上述程序时,我收到以下消息:如果 PostgreSQL 9 的构建失败并且您安装了 8.x 版。

So I run the following command:

所以我运行以下命令:

ARCHFLAGS="-arch x86_64" gem install pg

and this worked for me, I hope this helps someone :)

这对我有用,我希望这对某人有所帮助:)

回答by paninapress

Ok I also had this problem (psql is v 9.3.0 and ruby is v 2.1.2) and the solution that worked for me was setting the bundle config settings first:

好的,我也遇到了这个问题(psql 是 v 9.3.0,ruby 是 v 2.1.2),对我有用的解决方案是首先设置捆绑配置设置:

bundle config build.pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config

This answer finally helped me figure it out: https://stackoverflow.com/a/9235107/3546680

这个答案终于帮我弄明白了:https: //stackoverflow.com/a/9235107/3546680

回答by Ali Yazdani

I tried everything for hours but the following finally fixed it (I'm on OS X 10.9.4):

我尝试了几个小时,但以下最终修复了它(我在 OS X 10.9.4 上):

  1. Install Xcode command line tools (Apple Developer site)
  2. brew uninstall postgresql
  3. brew install postgresql
  4. ARCHFLAGS="-arch x86_64" gem install pg
  1. 安装 Xcode 命令行工具(Apple Developer 站点)
  2. brew 卸载 postgresql
  3. brew 安装 postgresql
  4. ARCHFLAGS="-arch x86_64" gem 安装 pg

回答by James Dela Cruz

easy step

简单的一步

  1. brew install postgresql
  2. gem install pg -v 'your version'
  1. brew install postgresql
  2. gem install pg -v 'your version'

回答by Matias Korhonen

I believe the “correct” answer would be to first configure PATH correctly for Postgres.app by adding the following to ~/.profile(.zshrcor ~/.zprofileif using ZSH):

我相信“正确”的答案是首先通过将以下内容添加到~/.profile.zshrc或者~/.zprofile如果使用 ZSH)为 Postgres.app 正确配置 PATH :

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

Then open a new tab or window in terminal and install the pggem with:

然后在终端中打开一个新选项卡或窗口并使用以下命令安装pggem:

ARCHFLAGS="-arch x86_64" gem install pg

Documented here:

记录在这里:

回答by Shannon Perkins

Similarly, after installing Mavericks bundle updatewas throwing an error on the pg gem, which is only used on production and not locally.

同样,在安装 Mavericks 后bundle update,在 pg gem 上抛出了一个错误,它仅用于生产而不是本地。

I use Brew to manage my packages and postgresql was already installed, but still I was getting the 'no pg_config' error.

我使用 Brew 来管理我的包并且已经安装了 postgresql,但我仍然收到“no pg_config”错误。

The fix was to just brew uninstall postgresql, then brew install postgresql. After which I was immediately able to successfully run bundle update.

解决方法是brew uninstall postgresql,然后brew install postgresql。之后我立即能够成功运行bundle update.

回答by jbheren

On OSX with Postgres installed in /Applications, I simply run the following command (change 0.20& 9.4according to your version)

在 /Applications 中安装了 Postgres 的 OSX 上,我只需运行以下命令(根据您的版本更改0.209.4

gem install pg -v '0.20' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config

You should have :

你应该有 :

Building native extensions with: '--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config' This could take a while... Successfully installed pg-0.20.

使用以下命令构建本机扩展:'--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config' 这可能需要一段时间......成功安装 pg-0.20。

回答by HosseinToussi

I spent a day on this and here's how I got it fixed:

我花了一天的时间来解决这个问题,这是我修复它的方法:

I found that global value of build.pg was set to: /opt/local/lib/postgresql91/bin/pg_configand that was not where postgres was installed.

我发现 build.pg 的全局值设置为:/opt/local/lib/postgresql91/bin/pg_config而这不是安装 postgres 的地方。

I fixed it with replacing the value of build.pg to: bundle config build.pg --with-pg-config=/usr/local/Cellar/postgresql/9.4.4/bin/pg_configwhich is where my postgresql installation is.

我通过将 build.pg 的值替换为:bundle config build.pg --with-pg-config=/usr/local/Cellar/postgresql/9.4.4/bin/pg_config这是我的 postgresql 安装所在的位置来修复它 。