2015-02-06 100 views
12

我最近試圖將我的rail 3.2 *應用程序升級到rails 4.2。*。但是,我在安裝'pg'寶石時停下了腳步。當我使用Google時,這些解決方案只與OSX有關。但我使用的是Ubuntu 14.04。需要對以下問題提出任何建議。rails 4.2.0:無法在ubuntu上安裝pg gem 14.04

我在我的機器上安裝了postgresql 9.3.5版本。

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

    /usr/local/rvm/rubies/ruby-2.1.2/bin/ruby extconf.rb 
checking for pg_config... yes 
Using config values from /usr/bin/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=/usr/local/rvm/rubies/ruby-2.1.2/bin/ruby 
    --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 

extconf failed, exit code 1 

Gem files will remain installed in /usr/local/rvm/gems/[email protected]/gems/pg-0.18.1 for inspection. 
Results logged to /usr/local/rvm/gems/[email protected]/extensions/x86_64-linux/2.1.0/pg-0.18.1/gem_make.out 
An error occurred while installing pg (0.18.1), and Bundler cannot continue. 
Make sure that `gem install pg -v '0.18.1'` succeeds before bundling. 
+0

@ MR-黑色請查看我的回答並接受它作爲正確答案 – 2015-03-19 19:39:26

回答

31

你需要的PostgreSQL

的頭
sudo apt-get install libpq-dev 

安裝PostgreSQL的開發包你也可以嘗試

sudo apt-get install postgresql-client 
sudo apt-get install postgresql postgresql-contrib 
+1

我已經安裝了這些依賴包。但是,我又失敗了。 – 2015-02-06 11:11:28

+1

你看起來在那http://stackoverflow.com/questions/3116015/how-to-install-gem-pg-on-ubuntu – 2015-02-06 11:13:48

+0

sudo apt-get install postgresql postgresql-contrib,這可能適合你 – 2015-02-06 11:21:15

10

陶然成在Ubuntu 14.04試圖gem install pg -v 0.18.1在PostgreSQL 9.4這個確切的問題

sudo apt-get install libpq-dev build-essential postgresql-server-dev-9.4 

基本上我是缺少postgresql-server-dev-${version}

在你的情況下,嘗試

sudo apt-get install libpq-dev build-essential postgresql-server-dev-9.3 
+3

謝謝!順便說一句,sudo apt-get安裝libpq-dev就足夠了。 – mondayguy 2015-05-09 17:46:03

+0

我一直在摔跤這幾天,沒有什麼幫助,直到'build-essential'軟件包安裝好了(對於gem pg 0.21)..我沒有看到其他任何地方,所以謝謝! – kevlarr 2017-09-04 17:59:32

+1

儘管剛試過用apt-get install libpq-dev gcc make而不是完整的build-essential, – kevlarr 2017-09-04 18:34:08

0

按照在Ubuntu這個命令16.04

sudo apt install libpq-dev postgresql-server 
sudo -u postgres createuser -s $(whoami); createdb $(whoami) 
gem install pg