rubygems - 无法安装 pg gem

标签 rubygems bundler pg

在花了几个小时试图弄清楚为什么它不起作用之后,我终于成功安装了“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来安装gem。有什么方法可以确保 bundle 程序使用正确的路径吗?

最佳答案

我在 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 gem 在执行此命令后安装,但仍然没有从 bundle 安装中安装,这很痛苦,因为我不知道除了 gem 'pg' 之外在 Gemfile 中要写什么

最终对我有用的是发现我的 pg_config 位于/Library/PostgreSQL/9.3/bin/pg_config 中,并且默认情况下 Gemfile bundle 安装在/usr/local/bin/pg_config 中查找

我刚刚运行了以下命令,奇迹就发生了。 bundle 配置 build.pg --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config

关于rubygems - 无法安装 pg gem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15234810/

相关文章:

ruby-on-rails - 如何卸载使用 `bundle install` 安装的所有 gem

macos - 使用 Mac Postgres App 很难 bundle pg

ruby - Bundler 可以根据我的 ruby​​ 版本(或受其他依赖项限制)自动安装最新版本吗?

ruby-on-rails - 无法在 Windows 7 上安装 Rmagick 和 Imagemagick

ruby-on-rails - 意外运行 $ gem update --system 后无法运行 rails 服务器

ruby - 在 Ruby 中的单词之间暂停时拆分语音音频

ruby-on-rails - RVM bundle 程序已安装错误 : Gem bundler is not installed, 首先运行 `gem install bundler`

postgresql - "SELECT * FROM $1"准备语句错误到 : error: syntax error at or near "$1"

ruby-on-rails - 如何将数据从我的生产数据库传输到 heroku 中的登台数据库?

ruby-on-rails - gem 不可用,即使在添加到 gemfile 并运行 bundle install 之后也是如此