rails install pg-找不到'libpq-fe.h标头


86
$ sudo bundle install

结果

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'但这无济于事

我的宝石文件

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 */

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

请帮帮我。谢谢。

对不起,此文字。您的帖子没有太多内容可以解释代码部分;请更清楚地说明您的情况。


1
您是如何安装PostgreSQL的?
Stefan


Answers:


184

只是做这个

$ sudo apt-get install libpq-dev

11
这对我来说就是+1
Mladen Danic

我尝试在Ubuntu 14.04上执行此操作,但它给了我这个:“ libpq-dev:依赖:libpq5(= 9.3.4-1),但要安装9.3.10-0ubuntu0.14.04”
Michael Lafayette

但是,当我尝试安装libpq5时,它说“ libpq5已经是最新版本”。
Michael Lafayette

PostgreSQL版本是:psql --version:psql(PostgreSQL)9.3.10。x86_64-unknown-linux-gnu上的PostgreSQL 9.3.10,由gcc(Ubuntu 4.8.2-19ubuntu1)4.8.2,64位编译
Michael Lafayette

1
辉煌!我正在编译的应用程序还需要libpq-fe.h使用明确指定路径--with-cflags=-I/usr/include/postgresql,以防其他人遇到相同的情况。
本·约翰逊

75

这是在回答可以在尝试安装PG宝石的时候找不到“的libpq-fe.h头

根据您的环境:

  • 苹果电脑: brew install postgresql
  • Ubuntu的sudo apt-get install libpq-dev
  • RHELyum install postgresql-devel

然后再跑gem install pg一次


1
我尝试在Ubuntu 14.04上执行此操作,但它给了我这个:“ libpq-dev:取决于:libpq5(= 9.3.4-1),但要安装9.3.10-0ubuntu0.14.04”
Michael Lafayette

但是,当我尝试安装libpq5时,它说“ libpq5已经是最新版本”。PostgreSQL也一样
Michael Lafayette

PostgreSQL版本是:psql --version:psql(PostgreSQL)9.3.10。x86_64-unknown-linux-gnu上的PostgreSQL 9.3.10,由gcc(Ubuntu 4.8.2-19ubuntu1)4.8.2,64位编译
Michael Lafayette

嗨,迈克尔,由于我不熟悉Ubuntu,我不确定我是否可以回答您的问题,但是您可能想在这里查看迈克尔·杜兰特的回答:stackoverflow.com/a/8887801/2484523
Phil

在Red Hat EL7上工作。我在Perl安装DBD :: Pg时缺少头文件。
Marcus

18

试试这个:

  1. brew安装postgresql
  2. 宝石安装pg
  3. 捆绑安装

15

在Fedora / RHEL系统上,可以做到这一点:

sudo yum install libpqxx-devel

为什么说:没有可用的软件包libpqxx-devel。
itsji10dra '16

1
yum list libpq *,然后是yum install libpqxx-devel.x86_64
erichfw

10
  • 因此:Ubuntu
  • 语言编程:C

$ sudo apt-get install libpq-dev

就我而言,我将目录路径错误。所以:

从: gcc -o lib_version lib_version.c -I/usr/include/postgresql -lpq -std=c99

至: gcc -o lib_version lib_version.c -I /usr/include/postgresql -lpq -std=c99

GL


5

在Mac OS X上,运行如下:

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

***/path/to/pg_config*** 是pg_config的路径



4

我在Amazon AMI上的Jenkins服务器上遇到了这个问题。

$ 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

1
啊! 优秀。特定的版本(9.6)也是我在AMI上遇到的障碍。
DaveGauer



1

在Mac上,请确保您的postgres已链接。你可以做到

brew link --overwrite postgresql

这为我解决了这个问题。


1

brew install postgresql 为我工作。

Postgresql的安装给出了另一个错误

Error: The following directories are not writable by your user: /usr/local/lib/pkgconfig /usr/local/share/info /usr/local/share/man/man3

通过将当前用户的访问权限授予该错误,已解决了该错误

sudo chown -R $(whoami) (path)


1

这是我在centos7发行版中部署我的应用程序时使用capistrano发生的。显然gem需要一些头文件,可以通过安装正确的开发包来解决这些头文件。

我通过运行修复了它 sudo yum search postgres | grep devel并找到了适用于我的postgres安装的正确软件包,该软件包为10。

然后只需运行sudo yum install postgresql10-devel,然后尤里卡!


你救了我的一天!找到正确的开发版本确实有帮助!
HoangLM

0

这为我工作:

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

0

我使用Ubuntu-16。我使用这里显示的方法:https : //www.postgresql.org/download/linux/ubuntu/ 安装postgresql-9.6;我曾经"sudo apt-get install libpq-dev"安装过devlib,但仍然无法正常工作。所以我使用的方法ln来建立软链接,在这里它是: sudo ln -s /usr/include/postgresql/libpq-fe.h /usr/include/; sudo ln -s /usr/include/postgresql/postgres_ext.h /usr/include/ 我终于解决了这个问题。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.