Ruby-on-rails rails install pg - 找不到“libpq-fe.h”头文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13086073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 20:55:30  来源:igfitidea点击:

rails install pg - Can't find the 'libpq-fe.h header

ruby-on-railsruby-on-rails-3sqlitepg

提问by Arthur Yakovlev

$ sudo bundle install

Result

结果

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.

I am make $ gem install pg -v '0.14.1'But this is not help

我是 make$ gem install pg -v '0.14.1'但这无济于事

My Gemfile

我的 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

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

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

Help me please. Thank you.

请帮帮我。谢谢你。

Sorry for this text. Your post does not have much context to explain the code sections; please explain your scenario more clearly.

对不起,这段文字。您的帖子没有太多上下文来解释代码部分;请更清楚地解释您的场景。

回答by Arthur Yakovlev

Just make this

做这个

$ sudo apt-get install libpq-dev

回答by Phil

This is answered in Can't find the 'libpq-fe.h header when trying to install pg gem

在尝试安装 pg gem 时找不到“libpq-fe.h 标头”中得到了回答

Depending on your environment:

取决于您的环境:

  • Mac:brew install postgresql
  • Ubuntu: sudo apt-get install libpq-dev
  • RHEL: yum install postgresql-devel
  • 苹果电脑:brew install postgresql
  • Ubuntusudo apt-get install libpq-dev
  • 瑞尔yum install postgresql-devel

Then run gem install pgagain

然后gem install pg再次运行

回答by Karol

Try this:

尝试这个:

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

回答by nicolasochem

On Fedora/RHEL systems this did the trick:

在 Fedora/RHEL 系统上,这成功了:

sudo yum install libpqxx-devel

回答by Jiemurat

On Mac OS X run like this:

在 Mac OS X 上运行如下:

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

***/path/to/pg_config***is path to pg_config

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

回答by Justin Fortier

I had this issue with a Jenkins server on Amazon AMI.

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

$ pg_config | grep VERSION
VERSION = PostgreSQL 9.4.9

Then depending on which version you need you can install the required 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

Then you can just install the corresponding version, in my case for version 9.4:

然后你可以安装相应的版本,在我的例子中是 9.4 版:

sudo yum install postgresql94-devel

回答by Gaurav Ragtah

For Amazon Linux:

对于亚马逊 Linux:

sudo yum install postgresql-devel

then run your command again

然后再次运行你的命令

回答by Braian Coronel

  • SO: Ubuntu
  • Language Programming: C
  • 所以:Ubuntu
  • 语言编程:C

$ sudo apt-get install libpq-dev

$ sudo apt-get install libpq-dev

In my case I was putting the directory path wrong. So:

就我而言,我把目录路径弄错了。所以:

From: 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

To: 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

GL

回答by Alter Lagos

For Alpine Linux, you can add libpq-fe.hwith:

对于Alpine Linux,您可以添加libpq-fe.h

apk add postgresql-dev

回答by Ashkinas

On mac make sure your postgres is linked. You can do it by

在 mac 上确保你的 postgres 已链接。你可以通过

brew link --overwrite postgresql

This fixed the issue for me.

这为我解决了这个问题。