【问题标题】:Error installing pg gem安装 pg gem 时出错
【发布时间】:2014-01-16 04:11:45
【问题描述】:

为了将我的 rails 应用程序部署到 heroku,我通过添加对我的 Gemfile 进行了更改

gem 'pg'

曾经做过

bundle install

我收到以下错误 -

Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using rake (10.1.1) 
Using i18n (0.6.9) 
Using minitest (4.7.5) 
Using multi_json (1.8.2) 
Using atomic (1.1.14) 
Using thread_safe (0.1.3) 
Using tzinfo (0.3.38) 
Using activesupport (4.0.0) 
Using builder (3.1.4) 
Using erubis (2.7.0) 
Using rack (1.5.2) 
Using rack-test (0.6.2) 
Using actionpack (4.0.0) 
Using mime-types (1.25.1) 
Using polyglot (0.3.3) 
Using treetop (1.4.15) 
Using mail (2.5.4) 
Using actionmailer (4.0.0) 
Using activemodel (4.0.0) 
Using activerecord-deprecated_finders (1.0.3) 
Using arel (4.0.1) 
Using activerecord (4.0.0) 
Using bundler (1.3.5) 
Using coffee-script-source (1.6.3) 
Using execjs (2.0.2) 
Using coffee-script (2.2.0) 
Using thor (0.18.1) 
Using railties (4.0.0) 
Using coffee-rails (4.0.1) 
Using hike (1.2.3) 
Using jbuilder (1.5.3) 
Using jquery-rails (3.0.4) 
Using json (1.8.1) 
Installing pg (0.17.1) 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/Users/aniruddhabarapatre1/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb 
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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
--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=/Users/aniruddhabarapatre1/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
--with-pg
--without-pg
--with-pg-config
--without-pg-config
--with-pg_config
--without-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}/


Gem files will remain installed in /Users/aniruddhabarapatre1/.rvm/gems/ruby-2.0.0-p247/gems/pg-0.17.1 for inspection.
Results logged to /Users/aniruddhabarapatre1/.rvm/gems/ruby-2.0.0-p247/gems/pg-0.17.1/ext/gem_make.out

An error occurred while installing pg (0.17.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.

我以为我的计算机上没有安装 PostgreSQL,因此下载它并没有用。 我尝试了其他几个选项并再次运行以下命令并出现类似错误。

gem install pg

【问题讨论】:

    标签: macos heroku ruby-on-rails-4 gem pg


    【解决方案1】:

    这可行 => env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config

    【讨论】:

      【解决方案2】:

      我卸载然后重新安装了 postgresql。然后我安装了 pg -v '0.17.1'。之后我跑了捆绑。它奏效了。

      【讨论】:

        【解决方案3】:

        把这件事弄明白了。

        因为我已经安装了 PostgreSQL.app。给出以下命令 -

        gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
        

        【讨论】:

        • 就我而言(使用 Postgres.app 9.3.2.0),正确的命令是: gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3 /bin/pg_config
        • 这对我有用。我必须运行 env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config - 确保匹配正确的 PG 版本。
        • 更新 Postgres.app 9.4 gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
        • 它在这里工作,但任何人都可以告诉为什么要这样做??
        【解决方案4】:

        你们有 postgres 开发库吗?

        【讨论】:

        • sudo apt-get install libpq-dev
        • 规范设置是使用 rvm 安装的 ruby​​ 和使用 postgres.app 或通过自制软件安装的 postgress。检查上面的链接。如果您仍然遇到问题,还请检查 rvm。
        猜你喜欢
        • 1970-01-01
        • 2013-05-21
        • 1970-01-01
        • 2016-10-04
        • 2014-08-20
        • 2012-07-11
        • 2011-08-11
        • 1970-01-01
        • 2017-08-27
        相关资源
        最近更新 更多