Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 用于rails的PostgreSQL gem赢得';t安装,即使同时安装了home brew和app_Ruby On Rails_Ruby_Ruby On Rails 3_Rubygems_Pg - Fatal编程技术网

Ruby on rails 用于rails的PostgreSQL gem赢得';t安装,即使同时安装了home brew和app

Ruby on rails 用于rails的PostgreSQL gem赢得';t安装,即使同时安装了home brew和app,ruby-on-rails,ruby,ruby-on-rails-3,rubygems,pg,Ruby On Rails,Ruby,Ruby On Rails 3,Rubygems,Pg,我已经试着按照这个让宝石工作,但它不会。我将我的项目设置为每个项目都有自己的gem,而不是生活在全球空间中的所有主题gem,然后我使用binstubs来允许我做bin/rails之类的事情 因此,对于每个项目,所有gems都安装到.bundle/gems/。总是给我带来最棘手问题的是posgresql。让我们来完成这些步骤 所以我跑: bundle 它说: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native

我已经试着按照这个让宝石工作,但它不会。我将我的项目设置为每个项目都有自己的gem,而不是生活在全球空间中的所有主题gem,然后我使用
binstubs
来允许我做
bin/rails
之类的事情

因此,对于每个项目,所有gems都安装到
.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版上安装了home 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,我也得到了精确的相同的错误

这是因为我在全球而不是本地安装pg gem吗?我怎样才能解决这个问题?这一个项目,每次我必须做一个
rm-rf.bundle/gems
时,都会反复引起这个问题


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

尝试
env ARCHFLAGS=“-arch x86_64”gem安装pg
当天结束时:

ARCHFLAGS="-arch x86_64" bundle install
这对我很管用

理由是:

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

您可以将此行添加到
~/.profile
或类似的:
导出
ARCHFLAGS=“-arch x86_64”


如需进一步阅读,请参阅:

确保先在计算机上安装Postgres

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


然后运行bundle安装

尝试安装postgresql开发包:

yum-y安装postgresql-devel


注意,上面的命令不会请求许可,因为
-y

确认了Antar Byrd的答案

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

为我工作

我使用了这个链接的这些命令

您需要安装头为postgreSQL的postgreSQL开发包

sudo-apt-get-install-libpq-dev

你也可以试试

sudo apt get安装postgresql客户端


sudo-apt-get-install-postgresql-postgresql-contrib

如果您使用的是完全相同的错误,那么该插件也可能很有用。我不知道发生了什么,也不知道为什么这个项目会如此失败。gem安装得很好,
失败,说明我需要确保gem首先安装。。。在我上面概述的其余错误中,我使用的是rvm,我使用的是ruby 2.2.0。我所有的项目都使用RVM。为了简单起见,如上所述,每个项目的所有gems都安装在
.bundle/gems/
上,以避免全局空间中的任何冲突。我还使用了
binstubs
来代替
rails
来执行
bin/rails
没有其他使用pg gem和2.2.0的项目面临这个问题,我还有三个其他项目。您尝试过任何解决方案吗?谢谢您发布这个问题并给出后续答案!我仍然有点不清楚这到底是为什么要修复它,但似乎我们现在告诉它使用64位体系结构,而这种解决方法只是因为与pg gem相关的东西没有正确编译为通用二进制文件。