2016-08-19 77 views
0

使用PostgreSQL 9.5.4開發一個新的Ruby on Rails 5.0應用程序。試圖安裝pg gem時遇到問題Rails 5,爲Postgres安裝pg gem時出錯9.5.4

軟件包安裝失敗,因爲它似乎無法在嘗試構建本機擴展時找到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 

回答

1

位後故障排除,下面是簡單的解決方法我曾經解決這個問題:

1)找到pg_configbin目錄中的PostgreSQL安裝下

# 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.