PostgreSQL gem for rails 不会安装,即使同时安装了 home brew 和应用程序

PostgreSQL gem for rails won't install, even when both home brew and app are installed

我曾尝试按照此 answer 来让 gem 工作,但它不会。我设置了我的项目,这样个人项目就有自己的 gems 而不是所有主题 gems 生活在全球 space,然后我使用 binstubs 允许我做类似 bin/rails.

的事情

因此每个项目的所有 gem 都安装到 .bundle/gems/。总是给我带来最棘手问题的是 posgresql。让我们完成这些步骤。

所以我运行:

bundle

它爆炸说:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
Using config values from /Applications/Postgres.app/Contents/Versions/9.3/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.

Provided configuration options:
    --with-opt-dir
    --without-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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
    --with-pg
    --without-pg
    --enable-windows-cross
    --disable-windows-cross
    --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}/
    --with-pqlib
    --without-pqlib
    --with-libpqlib
    --without-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib


Gem files will remain installed in /Users/Adam/Documents/Rails-Projects/AisisPlatform/.bundle/gems/gems/pg-0.18.1 for inspection.
Results logged to /Users/Adam/Documents/Rails-Projects/AisisPlatform/.bundle/gems/gems/pg-0.18.1/ext/gem_make.out
An error occurred while installing pg (0.18.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.1'` succeeds before bundling.

那么,因为我在 9.4.0 安装了家庭 brew 版本并且安装了 posgresql.app 然后我做了:

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

紧随其后,因为我用的是18.1

gem install pg -v '0.18.1'

我得到了:

Building native extensions.  This could take a while...
Successfully installed pg-0.18.1
invalid options: -f fivefish
(invalid options are ignored)
Parsing documentation for pg-0.18.1
Done installing documentation for pg after 2 seconds
1 gem installed

从那里我尝试了 bundle 好吧,我们回到原点,因为即使安装了 gem - 我得到了 EXACT 相同的错误。

这是因为我在全局而非本地安装 pg gem 吗?我怎样才能解决这个问题?这个项目,每次我必须做 rm -rf .bundle/gems 一遍又一遍地导致这个确切的问题。

我应该指出,即使我使用 home brew psql 我也会遇到同样的错误 pg_config 执行上述所有步骤,仅使用 home brew 版本,结果相同。

尝试env ARCHFLAGS="-arch x86_64" gem install pg

一天结束时是:

ARCHFLAGS="-arch x86_64" bundle install

对我有用。

原因是:

by default it tries to compile a universal binary, which apparently fails... so that environment variable makes it only compile the x86 version which is all you need

you can add this line to your ~/.profile or similar: export ARCHFLAGS="-arch x86_64"

如需进一步阅读,请参阅:This README for OSX

首先确保您的计算机上安装了 Postgres

对于 Ubuntu 系统:sudo apt-get install libpq-dev 在 RHEL 系统上:yum install postgresql-devel 对于 Mac:brew 安装 postgresql

然后运行捆绑安装

尝试安装 postgresql-devel 包:

yum -y install postgresql-devel

请注意,由于 -y

,上述命令不会请求许可

确认 Antarr Byrd 的回答,

 sudo env ARCHFLAGS='-arch x86_64' gem install pg  

对我有用。

我使用了这个 link

的这些命令

rails 4.2.0: can't install pg gem on ubuntu 14.04

您需要使用 PostgreSQL

的 header 安装 postgreSQL 开发包

sudo apt-get install libpq-dev

你也可以试试

sudo apt-get install postgresql-client

sudo apt-get install postgresql postgresql-contrib