即使安装了家用Brew和应用程序,也无法安装PostgreSQL gem for rails

The*_*ebs 8 ruby rubygems ruby-on-rails pg ruby-on-rails-3

我试过按照这个答案让宝石工作,但它不会.我的项目设置使得个人项目有自己的宝石而不是生活在全球空间的所有主题宝石,然后我用binstubs它来做我喜欢的事情bin/rails.

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

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

bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
Run Code Online (Sandbox Code Playgroud)

其次,因为我使用 18.1

gem install pg -v '0.18.1'
Run Code Online (Sandbox Code Playgroud)

我得到了:

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

从那里,我想bundle好了,我们又回到了起点,因为即使安装了宝石-我得到确切的同样的错误.

这是因为我在全局安装pg gem而不是本地安装吗?我怎样才能解决这个问题?这个项目,每次我都要做一次rm -rf .bundle/gems一遍又一遍地引起这个问题.

我应该指出即使我使用家庭酿造psql我也会得到同样的错误.pg_config执行上述所有步骤,只需使用家庭酿造版本,结果相同.

The*_*ebs 15

在一天结束时它是:

ARCHFLAGS="-arch x86_64" bundle install
Run Code Online (Sandbox Code Playgroud)

这对我有用.

原因是:

默认情况下,它会尝试编译一个通用的二进制文件,它显然会失败...所以环境变量使它只编译x86版本,这就是你需要的

您可以将此行添加到您的~/.profile或类似的:export ARCHFLAGS="-arch x86_64"

有关进一步阅读,请参阅:本OSME自述文件


小智 10

确保首先在计算机上安装Postgres

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

然后运行bundle install

  • 这是在Linux上做的正确的事情. (2认同)