gem install pg无法在Mac El Capitan上运行

时间:2015-10-26 01:55:58

标签: ruby-on-rails rubygems bundle pg

我尝试在Mac El Capitan上安装pg Gem,但我总是收到此错误:

    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=/Users/ricardolopes/Developer/homebrew/bin/pg_config
    Using config values from /Users/ricardolopes/Developer/homebrew/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/ricardolopes/Code/site-noticias/vendor/bundle/ruby/2.0.0/gems/pg-0.18.3 for inspection.
    Results logged to /Users/ricardolopes/Code/site-noticias/vendor/bundle/ruby/2.0.0/gems/pg-0.18.3/ext/gem_make.out
    An error occurred while installing pg (0.18.3), and Bundler cannot continue.
    Make sure that gem install pg -v '0.18.3' succeeds before bundling.

我也尝试过:

ARCHFLAGS="-arch x86_64" gem install pg

当我尝试时,我得到了:

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

但我运行bundle install并在本文开头发布了相同的错误。

我尝试从brew重新安装PostgresSQL。

3 个答案:

答案 0 :(得分:5)

试试这个:

  • brew update
  • brew install postgresql
  • sudo gem install pg -v'VERSION'

答案 1 :(得分:1)

这对我有用:
sudo gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config

如果与9.4不同,请记得将9.4更改为postgres版本。

答案 2 :(得分:-1)

对于一个基本的Rails应用程序,您可能已经安装了SQLite,但在您的Gemfile中,它可能只是:

gem 'sqlite3'

您是否只需要PostgreSQL进行制作?确保您的Gemfile具有以下内容:

group :production do gem 'pg' end

另外,请确保您的Gemfile只有用于开发的SQLite:

group :development do gem 'sqlite3' end

然后尝试运行bundle install