无法安装pg宝石

6

我花了几个小时的时间才成功地安装了'pg' gem,最终我输入了 sudo env ARCHFLAGS="-arch x86_64" gem install pg -v 0.12.2 -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config,这个方法非常好用。但是现在我在尝试使用 bundler 时仍然遇到同样的错误,所以我猜我并没有真正解决问题?无论如何,这里是 bundle install 的报错信息:

 Installing pg (0.12.2) 
    Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

            /Users/thomas/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb --with-pg-config=/usr/pgsql-9.2/bin/pg_config
    Using config values from /usr/pgsql-9.2/bin/pg_config
    sh: /usr/pgsql-9.2/bin/pg_config: No such file or directory
    sh: /usr/pgsql-9.2/bin/pg_config: No such file or directory
    checking for libpq-fe.h... yes
    checking for libpq/libpq-fs.h... yes
    checking for PQconnectdb() in -lpq... yes
    checking for PQconnectionUsedPassword()... yes
    checking for PQisthreadsafe()... yes
    checking for PQprepare()... yes
    checking for PQexecParams()... yes
    checking for PQescapeString()... yes
    checking for PQescapeStringConn()... yes
    checking for PQgetCancel()... yes
    checking for lo_create()... yes
    checking for pg_encoding_to_char()... yes
    checking for PQsetClientEncoding()... yes
    checking for rb_encdb_alias()... yes
    checking for rb_enc_alias()... yes
    checking for struct pgNotify.extra in libpq-fe.h... yes
    checking for unistd.h... yes
    checking for ruby/st.h... yes
    creating extconf.h
    creating Makefile

make
    compiling compat.c
    compiling pg.c
    pg.c: In function ‘pgconn_wait_for_notify’:
    pg.c:2117: warning: ‘rb_thread_select’ is deprecated (declared at /Users/thomas/.rvm/rubies/ruby-1.9.3-p392/include/ruby-1.9.1/ruby/intern.h:380)
    pg.c: In function ‘pgconn_block’:
    pg.c:2592: warning: format not a string literal and no format arguments
    pg.c:2598: warning: ‘rb_thread_select’ is deprecated (declared at /Users/thomas/.rvm/rubies/ruby-1.9.3-p392/include/ruby-1.9.1/ruby/intern.h:380)
    pg.c:2607: warning: format not a string literal and no format arguments
    linking shared-object pg_ext.bundle
    ld: warning: directory not found for option '-L-Wl,-undefined,dynamic_lookup'
    Undefined symbols for architecture x86_64:

....

    ld: symbol(s) not found for architecture x86_64
    collect2: ld returned 1 exit status
    make: *** [pg_ext.bundle] Error 1

我认为问题在于bundler尝试使用已删除的另一个postresql安装中的pg_config来安装宝石。 有没有办法确保bundler使用正确的路径?


3
找到了解决方案,我需要在运行bundle install之前运行bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config - Thomas Kuhlmann
1
哦,好的,我自己很少使用Bundler,但我会将其添加到README中,这样希望能帮助其他使用它的人。 - Michael Granger
仅为完整起见 - 我提到的路径需要与 Postgres App 结合使用。 - Thomas Kuhlmann
2个回答

12

我在bundle安装上卡了3天。尝试了各种方法,例如添加env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config

使用该命令后,我能够看到pg宝石被安装了,但仍然无法从bundle安装中安装, 这很让人头疼,因为我不知道在Gemfile中除了gem 'pg'之外还要写什么。

最终对我奏效的是找到我的pg_config位于/Library/PostgreSQL/9.3/bin/pg_config,而默认情况下Gemfile bundle install会在/usr/local/bin/pg_config中查找。

我只需要运行以下命令就可以了,bundle config build.pg --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config


找不到Gemfile或.bundle/目录。谢谢您的帮助。 - lopezdp

4

有一些需要改正的地方。对于那些使用Homebrew安装过postgres的人。

1) 在您的 ~/.bash_profile 中写入以下行

export ARCHFLAGS="-arch x86_64"

2) 重新启动终端

3) 执行以下命令

bundle config build.pg --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config (这必须是您的pg配置地址,因为不同版本的postgres可能会有所差异)

4) 通过运行此命令在本地安装pg一次

sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config

5) bundle install


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接