2012-10-26 111 views
37
$ sudo bundle install 

結果導軌安裝PG - 找不到「的libpq-fe.h頭

Fetching gem metadata from https://rubygems.org/........... 
Fetching gem metadata from https://rubygems.org/.. 
Using rake (0.9.2.2) 
Using i18n (0.6.1) 
Using multi_json (1.3.6) 
Using activesupport (3.2.8) 
Using builder (3.0.4) 
Using activemodel (3.2.8) 
Using erubis (2.7.0) 
Using journey (1.0.4) 
Using rack (1.4.1) 
Using rack-cache (1.2) 
Using rack-test (0.6.2) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.1.3) 
Using actionpack (3.2.8) 
Using mime-types (1.19) 
Using polyglot (0.3.3) 
Using treetop (1.4.11) 
Using mail (2.4.4) 
Using actionmailer (3.2.8) 
Using arel (3.0.2) 
Using tzinfo (0.3.33) 
Using activerecord (3.2.8) 
Using activeresource (3.2.8) 
Using bundler (1.2.1) 
Using coffee-script-source (1.4.0) 
Using execjs (1.4.0) 
Using coffee-script (2.2.0) 
Using rack-ssl (1.3.2) 
Using json (1.7.5) 
Using rdoc (3.12) 
Using thor (0.16.0) 
Using railties (3.2.8) 
Using coffee-rails (3.2.2) 
Using jquery-rails (2.1.3) 
Installing pg (0.14.1) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. 

     /usr/bin/ruby1.8 extconf.rb 
checking for pg_config... yes 
Using config values from /usr/bin/pg_config 
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application. 
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application. 
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=/usr/bin/ruby1.8 
    --with-pg 
    --without-pg 
    --with-pg-dir 
    --without-pg-dir 
    --with-pg-include 
    --without-pg-include=${pg-dir}/include 
    --with-pg-lib 
    --without-pg-lib=${pg-dir}/lib 
    --with-pg-config 
    --without-pg-config 
    --with-pg_config 
    --without-pg_config 

Gem files will remain installed in /var/lib/gems/1.8/gems/pg-0.14.1 for inspection. 
Results logged to /var/lib/gems/1.8/gems/pg-0.14.1/ext/gem_make.out 
An error occurred while installing pg (0.14.1), and Bundler cannot continue. 
Make sure that `gem install pg -v '0.14.1'` succeeds before bundling. 

我做$ gem install pg -v '0.14.1'但這不是幫助

我的Gemfile

source 'https://rubygems.org' 

#gem 'rails', '3.0.9' 

#gem 'sqlite3', '1.3.6', :group => :development 


gem 'rails', '3.2.8' 

# Bundle edge Rails instead: 
# gem 'rails', :git => 'git://github.com/rails/rails.git' 


gem 'sqlite3' 
gem 'pg' 
gem 'taps' 

gem 'json' 

# Gems used only for assets and not required 
# in production environments by default. 
group :assets do 
    gem 'sass-rails', '~> 3.2.3' 
    gem 'coffee-rails', '~> 3.2.1' 

    # See https://github.com/sstephenson/execjs#readme for more supported runtimes 
    # gem 'therubyracer', :platforms => :ruby 

    gem 'uglifier', '>= 1.0.3' 
end 

gem 'jquery-rails' 


#group :production do 
    #gem 'pg' 
#end 
#group :development do 
    #gem 'sqlite3' 
#end 

gem_make.out

/usr/bin/ruby1.8 extconf.rb 
checking for pg_config... yes 
Using config values from /usr/bin/pg_config 
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application. 
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application. 
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=/usr/bin/ruby1.8 
    --with-pg 
    --without-pg 
    --with-pg-dir 
    --without-pg-dir 
    --with-pg-include 
    --without-pg-include=${pg-dir}/include 
    --with-pg-lib 
    --without-pg-lib=${pg-dir}/lib 
    --with-pg-config 
    --without-pg-config 
    --with-pg_config 
    --without-pg_config 

mkmf.log

find_executable: checking for pg_config... -------------------- yes 

-------------------- 

find_header: checking for libpq-fe.h... -------------------- no 

"gcc -E -I. -I/usr/lib/ruby/1.8/i686-linux -I. -D_FORTIFY_SOURCE=2 -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -I -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -o conftest.i" 
conftest.c:1:22: fatal error: libpq-fe.h: No such file or directory 
compilation terminated. 
checked program was: 
/* begin */ 
1: #include <libpq-fe.h> 
/* end */ 

-------------------- 

請幫助我。謝謝。

對不起,這個文本。 您的文章沒有什麼太大的上下文解釋代碼段;請更清楚地解釋你的情況。

+0

你怎麼安裝PostgreSQL? – Stefan

+1

[找不到PostgreSQL客戶端庫(libpq)](http:// stackoverflow。com/questions/6209797/cant-find-the-postgresql-client-library-libpq) – skolima

+0

[試圖安裝pg gem時找不到'libpq-fe.h頭文件](http:// stackoverflow .com/questions/6040583/cant-find-the-libpq-fe-h-header-when-trying-to-install-pg-gem) – iconoclast

回答

91

只是使這種

$ sudo apt-get install libpq-dev 
+4

This did it for me +1 –

+5

這並不適合我... –

+0

我試圖在Ubuntu 14.04上做到這一點,但它給了我這個:「libpq-dev:取決於:libpq5(= 9.3.4-1),但9.3.10-0ubuntu0.14.04將被安裝」 –

1

試試這個:

sudo apt-get install libpq-dev 
gem install pg 

這將是工程!

13

試試這個:

  1. 釀造安裝PostgreSQL
  2. 創業板安裝PG
  3. 捆綁安裝
4

在Mac OS X上運行是這樣的:

gem install pg -- --with-pg-config=***/path/to/pg_config*** 

***/path/to/pg_config***是路徑到pg_confi摹

11

在Fedora/RHEL系統中,這做的伎倆:

sudo yum install libpqxx-devel 
+0

爲什麼說:沒有包libpqxx-devel可用。 – itsji10dra

+1

yum list libpq *後跟yum install libpqxx-devel.x86_64 – erichfw

22

這在Can't find the 'libpq-fe.h header when trying to install pg gem

回答根據您的環境:

  • 的Mac:brew install postgresql
  • Ubuntusudo apt-get install libpq-dev
  • RHELyum install postgresql-devel

然後再次運行gem install pg

+0

我試過在Ubuntu 14.04上做到這一點,但它給了我這個:「libpq-dev:Depends:libpq5(= 9.3.4-1)but 9.3.10- 0ubuntu0.14.04將被安裝「 –

+0

但是當我嘗試安裝libpq5時,它說」libpq5已經是最新的版本「。 PostgreSQL相同 –

+0

PostgreSQL版本爲:psql --version:psql(PostgreSQL)9.3.10。 PostgreSQL 9.3.10在x86_64-unknown-linux-gnu上,由gcc編譯(Ubuntu 4.8.2-19ubuntu1)4.8.2,64位 –

0

這爲我工作:

sudo gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config 
1

在Mac上確保你的Postgres連接。 您可以通過

brew link --overwrite postgresql 

這解決了我的問題。

0

我曾與亞馬遜AMI一詹金斯服務器這個問題。

$ pg_config | grep VERSION 
VERSION = PostgreSQL 9.4.9 

然後根據你的需要,你可以安裝所需的lib

$ sudo yum list postgresql* | grep devel 
postgresql92-devel.x86_64    9.2.18-1.59.amzn1   @amzn-main 
postgresql94-devel.x86_64    9.4.9-1.67.amzn1   @amzn-main 
postgresql8-devel.x86_64    8.4.20-5.52.amzn1   amzn-main 
postgresql93-devel.x86_64    9.3.14-1.62.amzn1   amzn-main 
postgresql95-devel.x86_64    9.5.4-1.71.amzn1   amzn-main 

然後,你可以安裝相應的版本,在我的情況下,9.4版的版本:

sudo yum install postgresql94-devel 
0

我使用Ubuntu-16。我用這裏顯示的方法:https://www.postgresql.org/download/linux/ubuntu/安裝postgresql-9.6; 我用"sudo apt-get install libpq-dev"安裝devlib.But它仍然無法正常工作。所以我使用的方法ln建立軟鏈接,在這裏它是: sudo ln -s /usr/include/postgresql/libpq-fe.h /usr/include/; sudo ln -s /usr/include/postgresql/postgres_ext.h /usr/include/ 我解決這個問題,在最後。