【问题标题】:Rails 5, Error installing pg gem for Postgres 9.5.4Rails 5,为 Postgres 9.5.4 安装 pg gem 时出错
【发布时间】:2016-08-19 02:13:54
【问题描述】:

使用 PostgreSQL 9.5.4 开发新的 Ruby on Rails 5.0 应用程序。尝试安装 pg gem 时遇到问题

捆绑安装失败,因为它似乎无法找到 pg_config 并且在尝试构建本机扩展时出错。

ERROR:  Error installing pg:
ERROR: Failed to build gem native extension.

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
    --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=/Users/brian.hooper/.rbenv/versions/2.3.0/bin/$(RUBY_BASE_NAME)
    --with-pg
    --without-pg
    --enable-windows-cross
    --disable-windows-cross
    --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}/lib

To see why this extension failed to compile, please check the mkmf.log

【问题讨论】:

    标签: ruby-on-rails postgresql pg


    【解决方案1】:

    经过一些故障排除后,这是我用来解决此问题的简单方法:

    1.) 在您的 postgresql 安装目录的 bin 目录下找到 pg_config

    # Example: 
    /Library/PostgreSQL/9.5/bin/pg_config
    

    2.) 从 Rails 项目的根目录运行以下捆绑命令

    bundle config build.pg --with-pg-config=<path_to_postgresql>/bin/pg_config
    
    # Example:
    bundle config build.pg --with-pg-config=/Library/PostgreSQL/9.5/bin/pg_config
    

    3.) 构建完成后,运行bundle install。正如您在下面看到的那样,pg gem 已成功安装。 Installing pg 0.18.4 with native extensions

    bundle install
    
    Fetching gem metadata from https://rubygems.org/...........
    Fetching version metadata from https://rubygems.org/...
    Fetching dependency metadata from https://rubygems.org/..
    Resolving dependencies.....
    Using rake 11.2.2
    Using concurrent-ruby 1.0.2
    Using i18n 0.7.0
    Using minitest 5.9.0
    Using thread_safe 0.3.5
    Using builder 3.2.2
    Using erubis 2.7.0
    Using mini_portile2 2.1.0
    Using pkg-config 1.1.7
    Using rack 2.0.1
    Using nio4r 1.2.1
    Using websocket-extensions 0.1.2
    Using mime-types-data 3.2016.0521
    Using arel 7.1.1
    Using bundler 1.11.2
    Using byebug 9.0.5
    Using coffee-script-source 1.10.0
    Using execjs 2.7.0
    Using method_source 0.8.2
    Using thor 0.19.1
    Using debug_inspector 0.0.2
    Using ffi 1.9.14
    Using multi_json 1.12.1
    Using rb-fsevent 0.9.7
    Installing pg 0.18.4 with native extensions
    Using puma 3.6.0
    Using sass 3.4.22
    Using tilt 2.0.5
    Using spring 1.7.2
    Using turbolinks-source 5.0.0
    Using tzinfo 1.2.2
    Using nokogiri 1.6.8
    Using rack-test 0.6.3
    Using sprockets 3.7.0
    Using websocket-driver 0.6.4
    Using mime-types 3.1 
    Using coffee-script 2.4.1
    Using uglifier 3.0.1
    Using rb-inotify 0.9.7
    Using turbolinks 5.0.1
    Using activesupport 5.0.0.1
    Using loofah 2.0.3
    Using mail 2.6.4
    Using listen 3.0.8
    Using rails-dom-testing 2.0.1
    Using globalid 0.3.7
    Using activemodel 5.0.0.1
    Using jbuilder 2.6.0
    Using rails-html-sanitizer 1.0.3
    Using spring-watcher-listen 2.0.0
    Using activejob 5.0.0.1
    Using activerecord 5.0.0.1
    Using actionview 5.0.0.1
    Using actionpack 5.0.0.1
    Using actioncable 5.0.0.1
    Using actionmailer 5.0.0.1
    Using railties 5.0.0.1
    Using sprockets-rails 3.1.1
    Using coffee-rails 4.2.1
    Using jquery-rails 4.1.1
    Using web-console 3.3.1
    Using rails 5.0.0.1
    Using sass-rails 5.0.6
    Bundle complete! 15 Gemfile dependencies, 63 gems now installed.
    Use `bundle show [gemname]` to see where a bundled gem is installed.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-21
      • 2012-07-11
      • 2014-01-16
      • 1970-01-01
      • 1970-01-01
      • 2016-10-04
      • 2016-05-02
      • 1970-01-01
      相关资源
      最近更新 更多