找不到“libpq-fe。在尝试安装pg gem时,h标头。

时间:2023-01-16 17:41:08

I am using the Ruby on Rails 3.1 pre version. I like to use PostgreSQL, but the problem is installing the pg gem. It gives me the following error:

我正在使用Ruby on Rails 3.1前版本。我喜欢使用PostgreSQL,但问题是安装pg gem。它给了我以下错误:

$ gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

        /home/u/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb
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=/home/u/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
    --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 /home/u/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.11.0 for inspection.
Results logged to /home/u/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.11.0/ext/gem_make.out

How do I solve this problem?

我该如何解决这个问题?

35 个解决方案

#1


966  

It looks like in Ubuntu that header is part of the libpq-dev package (at least in the following Ubuntu versions: 11.04 (Natty Narwhal), 10.04 (Lucid Lynx), 11.10 (Oneiric Ocelot), 12.04 (Precise Pangolin) and 14.04 (Trusty Tahr)):

在Ubuntu中,header是libpq-dev包的一部分(至少在以下Ubuntu版本中:11.04 (Natty Narwhal), 10.04 (Lucid Lynx), 11.10 (Oneiric Ocelot), 12.04(精确穿山林)和14.04 (Trusty Tahr)):

...
/usr/include/postgresql/libpq-fe.h
...

So try installing libpq-dev or its equivalent for your OS:

因此,请尝试安装libpq-dev或其对应的操作系统:

  • For Ubuntu systems: sudo apt-get install libpq-dev
  • 对于Ubuntu系统:sudo apt-get安装libpq-dev。
  • On Red Hat Linux (RHEL) systems: yum install postgresql-devel
  • 在Red Hat Linux (RHEL)系统:yum安装postgresql-devel。
  • For Mac Homebrew: brew install postgresql
  • Mac Homebrew: brew安装postgresql。
  • For Mac MacPorts PostgreSQL: gem install pg -- --with-pg-config=/opt/local/lib/postgresql[version number]/bin/pg_config
  • 对于Mac MacPorts PostgreSQL: gem安装pg -- -配置=/opt/local/lib/ PostgreSQL[版本号]/bin/pg_config。
  • For OpenSuse: zypper in postgresql-devel
  • OpenSuse: postgresql-devel的zypper。

#2


120  

On macOS (previously Mac OS X and OS X), use Homebrew to install the proper headers:

在macOS上(之前的Mac OS X和OS X),使用Homebrew来安装适当的标题:

brew install postgresql

and then running

然后运行

gem install pg

should work.

应该工作。

#3


110  

I had also tried doing gem install libpq-dev, but I received this error:

我还尝试了gem安装libpq-dev,但我收到了这个错误:

Can't find the 'libpq-fe.h header
*** extconf.rb failed ***

However I found that installing with sudo apt-get (which I try to avoid using with Ruby on Rails) worked, i.e.

然而,我发现安装sudo apt-get(我尽量避免使用Ruby on Rails)工作,也就是。

sudo apt-get install libpq-dev
# or
apt-get install postgres-server-dev-{pg.version}
# for postgresql 9.4 on Ubuntu 14.04

then I was able to do

然后我就能做了。

gem install pg

without issues.

没有问题。

#4


40  

I could solve this in another way. I didn't find the library on my system. Thus I installed it using an app from PostgreSQL main website. In my case (OS X) I found the file under /Library/PostgreSQL/9.1/include/ once the installation was over. You may also have the file somewhere else depending on your system if you already have PostgreSQL installed.

我可以用另一种方法求解。我在系统上找不到图书馆。因此,我使用PostgreSQL主网站的一个应用程序安装了它。在我的例子中(OS X),我找到了/Library/PostgreSQL/9.1/包含/安装结束后的文件。如果您已经安装了PostgreSQL,那么您还可以在其他地方使用该文件,这取决于您的系统。

Thanks to this link on how to add an additional path for gem installation, I could point the gem to the lib with this command:

由于这个链接关于如何为gem安装添加额外的路径,我可以通过以下命令将gem指向lib:

export CONFIGURE_ARGS="with-pg-include=/Library/PostgreSQL/9.1/include/"
gem install pg

After that, it works, because it now knows where to find the missing library. Just replace the path with the right location for your libpq-fe.h

在那之后,它起作用了,因为它现在知道在哪里找到丢失的库。只需替换为libpq-fe.h的正确位置的路径。

#5


20  

Can't find the libpq-fe.h header

找不到libpq-fe。h头

i had success on CentOS 7.0.1406 running the following commands:

我在CentOS 7.0.1406上取得了成功,运行如下命令:

~ % psql --version # => psql (PostgreSQL) 9.4.1
yum install libpqxx-devel
gem install pg -- --with-pg-config=/usr/pgsql-9.4/bin/pg_config

Alternatively, you can configure bundler to always install pg with these options (helpful for running bundler in deploy environments),

或者,您可以配置bundler来始终使用这些选项安装pg(对于在部署环境中运行bundler很有帮助),

  • bundle config build.pg --with-pg-config=/usr/pgsql-9.4/bin/pg_config
  • 包配置构建。pg - with-pg-config = / usr / bin / pg_config / pgsql - 9.4

#6


20  

For CentOS 6.4,

CentOS 6.4,

yum install postgresql-devel
gem install pg

worked well!

工作得很好!

#7


12  

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的路径。

#8


12  

In my case it was package postgresql-server-dev-8.4 (I am on Ubuntu 11.04 (Natty Narwhal), 64 bits).

在我的例子中,它是包postgresql-server-dev-8.4(我在Ubuntu 11.04 (Natty Narwhal), 64位)。

#9


12  

Just for the record:

只是为了记录:

Ruby on Rails 4 application in OS X with PostgresApp (in this case 0.17.1 version needed - kind of an old project):

Ruby on Rails 4应用程序在OS X中使用PostgresApp(在本例中是0.17.1版本需要的一种旧项目):

gem install pg -v '0.17.1' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config

#10


9  

The right answer for Mac users with Postgres.app is to build against the libpq provided with that package. For example, with the 9.4 release (current as of this writing), all you need is:

使用Postgres的Mac用户的正确答案。应用程序是针对该包提供的libpq进行构建。例如,在9.4版本中(在撰写本文时),您所需要的是:

export CONFIGURE_ARGS="with-pg-include=/Applications/Postgres.app/Contents/Versions/9.4/include"
gem install pg

This will keep your pg gem in sync with exactly the version of PostgreSQL you have installed. Installing something from Homebrew is a waste in this case.

这将使您的pg gem与您安装的PostgreSQL的版本保持同步。在这种情况下,从自制程序中安装一些东西是一种浪费。

#11


8  

I had the same issue on Amazon Linux. I could find the header libpq-fe.h, but somehow it didn't work.

我在Amazon Linux上也有同样的问题。我可以找到libpq-fe的头。h,但不管怎么说,它没有起作用。

It came from the different versions of the packages that were installed through the different users on the machine. PostgreSQL 9.2 and PostgreSQL 9.3 were installed. So, make sure of your PostgreSQL version before including the libraries.

它来自于在机器上通过不同用户安装的不同版本的包。安装了PostgreSQL 9.2和PostgreSQL 9.3。因此,在包含库之前,请确保您的PostgreSQL版本。

For me, the magic command line was:

对我来说,神奇的命令行是:

sudo yum install postgresql93 postgresql93-server postgresql93-libs postgresql93-contrib postgresql93-devel

Source: An almost idiot's guide to install PostgreSQL 9.3, PostGIS 2.1 and pgRouting with Yum

来源:一个几乎是白痴的指南安装PostgreSQL 9.3, PostGIS 2.1和pgRouting with Yum。

#12


6  

A more general answer for any Debian-based distribution (which includes Ubuntu) is the following. First, install the apt-file package running as root:

对于任何基于debian的发行版(包括Ubuntu)来说,一个更普遍的答案是以下内容。首先,安装以root身份运行的apt文件包:

apt-get install apt-file

This allows you to search for packages containing a file. Then, update its database using

这允许您搜索包含文件的包。然后,使用它更新数据库。

apt-file update

(this can be run as normal user). Then, look for the missing header using:

(这可以作为普通用户运行)。然后,使用以下方法查找丢失的标题:

apt-file search libpq-fe.h

On my machine, this gives:

在我的机器上,这是:

libpq-dev: /usr/include/postgresql/libpq-fe.h
postgres-xc-server-dev: /usr/include/postgres-xc/server/gtm/libpq-fe.h

There you go !

你走吧!

#13


4  

I recently upgraded to Mac OS X v10.10 (Yosemite) and was having difficulty building the pg gem.

我最近升级到Mac OS X v10.10 (Yosemite),并且很难构建pg gem。

The error reported was the typical:

报告的错误是典型的:

Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... *** extconf.rb failed ***

My solution was to gem uninstall pg and then bundle update pg to replace the gem with the latest. I did run brew update; brew upgrade after the Yosemite install to get the latest versions of packages I had installed previously.

我的解决方案是gem卸载pg,然后绑定更新pg以替换最新的gem。我确实运行了brew更新;在Yosemite安装后进行brew升级,以获得我之前安装的软件包的最新版本。

#14


4  

On a Mac, I solved it using this code:

在Mac上,我用这个代码解决了这个问题:

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

#15


3  

On CentOS,I installed libpq-dev package using below command

在CentOS中,我使用下面的命令安装了libpq-dev包。

yum install postgresql-devel

Executing gem install pg returned the same error as "No pg_config... trying anyway. If building fails, please try again with --with-pg-config=/path/to/pg_config".

执行gem安装pg返回的错误与“No pg_config…不管怎样。如果构建失败,请再次尝试使用—with-pg-config=/path/to/pg_config。

Installing the gem as below solved my problem

安装下面的gem解决了我的问题。

gem install pg -- --with-pg-config=/usr/pgsql-x.x/bin/pg_config

#16


3  

I am running Postgres.app on a Mac and I had to

我跑步Postgres。Mac上的应用程序,我不得不这么做。

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin

first. Then

第一。然后

bundle install

worked for me.

为我工作。

#17


3  

I had the same problem on Mac OS, but I installed the PostgreSQL gem easily by using the following in a terminal:

我在Mac OS上遇到了同样的问题,但是我在一个终端上很容易地安装了PostgreSQL gem:

ARCHFLAGS="-arch x86_64" gem install pg

(I installed PostgreSQL first with brew install postgresql.)

(我先安装了PostgreSQL和brew安装PostgreSQL。)

#18


3  

I found this answer, and it was the only one that worked for me (Mac OS) - after researching for about two days:

我找到了这个答案,这是我唯一为我工作的(Mac OS)——在研究了大约两天之后:

$ sudo su

$ env ARCHFLAGS="-arch x86_64" gem install pg

Building native extensions.  This could take a while...
Successfully installed pg-0.11.0
1 gem installed
Installing ri documentation for pg-0.11.0...
Installing RDoc documentation for pg-0.11.0...

See Stack Overflow question Can't find the PostgreSQL client library (libpq).

查看堆栈溢出问题无法找到PostgreSQL客户端库(libpq)。

#19


2  

On FreeBSD (9.1) the necessary package is /usr/ports/database/postgresql-server* which when installed will also install the required header file that makes the gem install of "pg" fail. This answer here helped me find the solution but the difference in package names required a bit of searching.

在FreeBSD(9.1)中,必要的包是/usr/ports/database/postgresql-server*,当安装时,它还会安装所需的头文件,使gem安装“pg”失败。这个答案帮助我找到了解决方案,但是包名的不同需要一点搜索。

Hopefully this helps someone avoid a bit of head scratching when searching for the "-dev" package on a FreeBSD system!

希望这能帮助人们在FreeBSD系统中搜索“-dev”包时避免一些挠头!

#20


2  

On Debian 7.0, 64-bit (Wheezy), just run:

在Debian 7.0, 64位(Wheezy),运行:

sudo apt-get install libpq-dev

After you successfully installed libpq-dev, run:

成功安装libpq-dev后,运行:

bundle install

#21


2  

Under CentOS 6.5 (Squeeze) I created a file:

在CentOS 6.5(挤压)下,我创建了一个文件:

$ sudo touch /etc/profile.d/psql.sh

with content:

与内容:

pathmunge /usr/pgsql-9.3/bin

Note here, you should set your PostgreSQL path with the pg_config file. You can find this with the command:

注意,您应该使用pg_config文件设置您的PostgreSQL路径。您可以通过以下命令找到:

$ sudo find / -iname pg_config

Save the file:

保存文件:

$ sudo chmod +x /etc/profile.d/ruby.sh

and try to execute your command again.

并尝试再次执行您的命令。

Note: Anytime you change the Bash configuration - changing the profile.d configuration - you should reload Bash.

注意:任何时候更改Bash配置——更改配置文件。d配置-您应该重新加载Bash。

#22


2  

The location of libpq-fe.h depends on where your PostgreSQL install is (which depends on how you installed it). Use locate (http://en.wikipedia.org/wiki/Locate_%28Unix%29) to find the libpq-fe.h file on your machine. If it exists, it will be in the include directory of your PostgreSQL install.

libpq-fe的位置。h取决于您的PostgreSQL安装在哪里(这取决于您如何安装它)。使用locate (http://en.wikipedia.org/wiki/Locate_%28Unix%29)找到libpq-fe。h文件在你的机器上。如果它存在,它将在您的PostgreSQL安装的include目录中。

$ locate libpq-fe.h
/Library/PostgreSQL/9.1/include/libpq-fe.h

The bin directory, which contains pg_config, will be in the same directory as the include directory. As the error suggests, use the --with-pg-config option to install the gem:

包含pg_config的bin目录将与include目录在同一个目录中。正如错误提示的那样,使用-with-pg-config选项来安装gem:

$ gem install pg --with-pg-config="/Library/PostgreSQL/9.1/bin/pg_config"

Note that you may need to run updatedb if you have never used locate or if you haven't updated since installing PostgreSQL.

注意,如果您从未使用过位置,或者自从安装PostgreSQL之后没有更新,您可能需要运行updatedb。

#23


2  

I just had this on OSX running brew and postgres@9.4.

我刚刚在OSX上运行brew和postgres@9.4。

My fix was this:

我的修复是这样的:

CONFIGURE_ARGS="with-pg-include=/usr/local/opt/postgresql@9.4/include/" bundle install

#24


1  

For AltLinux the package postgresqlx.x-devel (in my case postgresql9.5-devel) must be installed:

对于AltLinux,包postgresqlx。x-devel(在我的例子中是postgresql9.5-devel)必须安装:

apt-get install postgresql9.5-devel

#25


1  

I solved this installing the 'postgresql-common' package. This package provides the pg_config binary which is most likely what you were missing.

我解决了这个安装“postgresql-common”包的问题。这个包提供了pg_config二进制文件,它很可能是您丢失的。

#26


1  

I was having a similar problem, and this fixed it for me:

我有一个类似的问题,这个问题解决了:

gem install do_postgres -- --with-pgsql-server-dir=/Applications/Postgres.app/Contents/MacOS --with-pgsql-server-include=/Applications/Postgres.app/Contents/MacOS/include/server

Source:

来源:

https://gist.github.com/oisin/6562181

https://gist.github.com/oisin/6562181

#27


1  

On OS X 10.9 (Mavericks), I brew-installed postgresql, and I then had to rvm reinstall my Ruby. I am happy now :)

在OS X 10.9 (Mavericks)上,我安装了postgresql,然后我不得不重新安装我的Ruby。我现在很高兴:)

#28


1  

I finally solved this problem, but not using the previously described methods.

我最终解决了这个问题,但没有使用前面描述的方法。

Using brew install postgresql, I find out that it had already been installed, but not linked.

使用brew安装postgresql,我发现它已经安装了,但没有链接。

  1. Find out where PostgreSQL is installed, and delete it,

    找出PostgreSQL的安装位置,并删除它,

  2. Then brew install postgresql again,

    然后再重新安装postgresql,

  3. brew link postgresql

    酿造postgresql的联系

  4. gem install pg

    gem安装pg

#29


1  

On Ubuntu, install the "libpq-dev" to get rid of this issue.

在Ubuntu上,安装“libpq-dev”来处理这个问题。

sudo apt-get install libpq-dev

#30


1  

For MacOS without installing PostgreSQL server:

对于不安装PostgreSQL服务器的MacOS:

brew install libpq
gem install pg -- --with-pg-config="/usr/local/Cellar/libpq/9.6.6/bin/pg_config"

#1


966  

It looks like in Ubuntu that header is part of the libpq-dev package (at least in the following Ubuntu versions: 11.04 (Natty Narwhal), 10.04 (Lucid Lynx), 11.10 (Oneiric Ocelot), 12.04 (Precise Pangolin) and 14.04 (Trusty Tahr)):

在Ubuntu中,header是libpq-dev包的一部分(至少在以下Ubuntu版本中:11.04 (Natty Narwhal), 10.04 (Lucid Lynx), 11.10 (Oneiric Ocelot), 12.04(精确穿山林)和14.04 (Trusty Tahr)):

...
/usr/include/postgresql/libpq-fe.h
...

So try installing libpq-dev or its equivalent for your OS:

因此,请尝试安装libpq-dev或其对应的操作系统:

  • For Ubuntu systems: sudo apt-get install libpq-dev
  • 对于Ubuntu系统:sudo apt-get安装libpq-dev。
  • On Red Hat Linux (RHEL) systems: yum install postgresql-devel
  • 在Red Hat Linux (RHEL)系统:yum安装postgresql-devel。
  • For Mac Homebrew: brew install postgresql
  • Mac Homebrew: brew安装postgresql。
  • For Mac MacPorts PostgreSQL: gem install pg -- --with-pg-config=/opt/local/lib/postgresql[version number]/bin/pg_config
  • 对于Mac MacPorts PostgreSQL: gem安装pg -- -配置=/opt/local/lib/ PostgreSQL[版本号]/bin/pg_config。
  • For OpenSuse: zypper in postgresql-devel
  • OpenSuse: postgresql-devel的zypper。

#2


120  

On macOS (previously Mac OS X and OS X), use Homebrew to install the proper headers:

在macOS上(之前的Mac OS X和OS X),使用Homebrew来安装适当的标题:

brew install postgresql

and then running

然后运行

gem install pg

should work.

应该工作。

#3


110  

I had also tried doing gem install libpq-dev, but I received this error:

我还尝试了gem安装libpq-dev,但我收到了这个错误:

Can't find the 'libpq-fe.h header
*** extconf.rb failed ***

However I found that installing with sudo apt-get (which I try to avoid using with Ruby on Rails) worked, i.e.

然而,我发现安装sudo apt-get(我尽量避免使用Ruby on Rails)工作,也就是。

sudo apt-get install libpq-dev
# or
apt-get install postgres-server-dev-{pg.version}
# for postgresql 9.4 on Ubuntu 14.04

then I was able to do

然后我就能做了。

gem install pg

without issues.

没有问题。

#4


40  

I could solve this in another way. I didn't find the library on my system. Thus I installed it using an app from PostgreSQL main website. In my case (OS X) I found the file under /Library/PostgreSQL/9.1/include/ once the installation was over. You may also have the file somewhere else depending on your system if you already have PostgreSQL installed.

我可以用另一种方法求解。我在系统上找不到图书馆。因此,我使用PostgreSQL主网站的一个应用程序安装了它。在我的例子中(OS X),我找到了/Library/PostgreSQL/9.1/包含/安装结束后的文件。如果您已经安装了PostgreSQL,那么您还可以在其他地方使用该文件,这取决于您的系统。

Thanks to this link on how to add an additional path for gem installation, I could point the gem to the lib with this command:

由于这个链接关于如何为gem安装添加额外的路径,我可以通过以下命令将gem指向lib:

export CONFIGURE_ARGS="with-pg-include=/Library/PostgreSQL/9.1/include/"
gem install pg

After that, it works, because it now knows where to find the missing library. Just replace the path with the right location for your libpq-fe.h

在那之后,它起作用了,因为它现在知道在哪里找到丢失的库。只需替换为libpq-fe.h的正确位置的路径。

#5


20  

Can't find the libpq-fe.h header

找不到libpq-fe。h头

i had success on CentOS 7.0.1406 running the following commands:

我在CentOS 7.0.1406上取得了成功,运行如下命令:

~ % psql --version # => psql (PostgreSQL) 9.4.1
yum install libpqxx-devel
gem install pg -- --with-pg-config=/usr/pgsql-9.4/bin/pg_config

Alternatively, you can configure bundler to always install pg with these options (helpful for running bundler in deploy environments),

或者,您可以配置bundler来始终使用这些选项安装pg(对于在部署环境中运行bundler很有帮助),

  • bundle config build.pg --with-pg-config=/usr/pgsql-9.4/bin/pg_config
  • 包配置构建。pg - with-pg-config = / usr / bin / pg_config / pgsql - 9.4

#6


20  

For CentOS 6.4,

CentOS 6.4,

yum install postgresql-devel
gem install pg

worked well!

工作得很好!

#7


12  

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的路径。

#8


12  

In my case it was package postgresql-server-dev-8.4 (I am on Ubuntu 11.04 (Natty Narwhal), 64 bits).

在我的例子中,它是包postgresql-server-dev-8.4(我在Ubuntu 11.04 (Natty Narwhal), 64位)。

#9


12  

Just for the record:

只是为了记录:

Ruby on Rails 4 application in OS X with PostgresApp (in this case 0.17.1 version needed - kind of an old project):

Ruby on Rails 4应用程序在OS X中使用PostgresApp(在本例中是0.17.1版本需要的一种旧项目):

gem install pg -v '0.17.1' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config

#10


9  

The right answer for Mac users with Postgres.app is to build against the libpq provided with that package. For example, with the 9.4 release (current as of this writing), all you need is:

使用Postgres的Mac用户的正确答案。应用程序是针对该包提供的libpq进行构建。例如,在9.4版本中(在撰写本文时),您所需要的是:

export CONFIGURE_ARGS="with-pg-include=/Applications/Postgres.app/Contents/Versions/9.4/include"
gem install pg

This will keep your pg gem in sync with exactly the version of PostgreSQL you have installed. Installing something from Homebrew is a waste in this case.

这将使您的pg gem与您安装的PostgreSQL的版本保持同步。在这种情况下,从自制程序中安装一些东西是一种浪费。

#11


8  

I had the same issue on Amazon Linux. I could find the header libpq-fe.h, but somehow it didn't work.

我在Amazon Linux上也有同样的问题。我可以找到libpq-fe的头。h,但不管怎么说,它没有起作用。

It came from the different versions of the packages that were installed through the different users on the machine. PostgreSQL 9.2 and PostgreSQL 9.3 were installed. So, make sure of your PostgreSQL version before including the libraries.

它来自于在机器上通过不同用户安装的不同版本的包。安装了PostgreSQL 9.2和PostgreSQL 9.3。因此,在包含库之前,请确保您的PostgreSQL版本。

For me, the magic command line was:

对我来说,神奇的命令行是:

sudo yum install postgresql93 postgresql93-server postgresql93-libs postgresql93-contrib postgresql93-devel

Source: An almost idiot's guide to install PostgreSQL 9.3, PostGIS 2.1 and pgRouting with Yum

来源:一个几乎是白痴的指南安装PostgreSQL 9.3, PostGIS 2.1和pgRouting with Yum。

#12


6  

A more general answer for any Debian-based distribution (which includes Ubuntu) is the following. First, install the apt-file package running as root:

对于任何基于debian的发行版(包括Ubuntu)来说,一个更普遍的答案是以下内容。首先,安装以root身份运行的apt文件包:

apt-get install apt-file

This allows you to search for packages containing a file. Then, update its database using

这允许您搜索包含文件的包。然后,使用它更新数据库。

apt-file update

(this can be run as normal user). Then, look for the missing header using:

(这可以作为普通用户运行)。然后,使用以下方法查找丢失的标题:

apt-file search libpq-fe.h

On my machine, this gives:

在我的机器上,这是:

libpq-dev: /usr/include/postgresql/libpq-fe.h
postgres-xc-server-dev: /usr/include/postgres-xc/server/gtm/libpq-fe.h

There you go !

你走吧!

#13


4  

I recently upgraded to Mac OS X v10.10 (Yosemite) and was having difficulty building the pg gem.

我最近升级到Mac OS X v10.10 (Yosemite),并且很难构建pg gem。

The error reported was the typical:

报告的错误是典型的:

Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... *** extconf.rb failed ***

My solution was to gem uninstall pg and then bundle update pg to replace the gem with the latest. I did run brew update; brew upgrade after the Yosemite install to get the latest versions of packages I had installed previously.

我的解决方案是gem卸载pg,然后绑定更新pg以替换最新的gem。我确实运行了brew更新;在Yosemite安装后进行brew升级,以获得我之前安装的软件包的最新版本。

#14


4  

On a Mac, I solved it using this code:

在Mac上,我用这个代码解决了这个问题:

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

#15


3  

On CentOS,I installed libpq-dev package using below command

在CentOS中,我使用下面的命令安装了libpq-dev包。

yum install postgresql-devel

Executing gem install pg returned the same error as "No pg_config... trying anyway. If building fails, please try again with --with-pg-config=/path/to/pg_config".

执行gem安装pg返回的错误与“No pg_config…不管怎样。如果构建失败,请再次尝试使用—with-pg-config=/path/to/pg_config。

Installing the gem as below solved my problem

安装下面的gem解决了我的问题。

gem install pg -- --with-pg-config=/usr/pgsql-x.x/bin/pg_config

#16


3  

I am running Postgres.app on a Mac and I had to

我跑步Postgres。Mac上的应用程序,我不得不这么做。

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin

first. Then

第一。然后

bundle install

worked for me.

为我工作。

#17


3  

I had the same problem on Mac OS, but I installed the PostgreSQL gem easily by using the following in a terminal:

我在Mac OS上遇到了同样的问题,但是我在一个终端上很容易地安装了PostgreSQL gem:

ARCHFLAGS="-arch x86_64" gem install pg

(I installed PostgreSQL first with brew install postgresql.)

(我先安装了PostgreSQL和brew安装PostgreSQL。)

#18


3  

I found this answer, and it was the only one that worked for me (Mac OS) - after researching for about two days:

我找到了这个答案,这是我唯一为我工作的(Mac OS)——在研究了大约两天之后:

$ sudo su

$ env ARCHFLAGS="-arch x86_64" gem install pg

Building native extensions.  This could take a while...
Successfully installed pg-0.11.0
1 gem installed
Installing ri documentation for pg-0.11.0...
Installing RDoc documentation for pg-0.11.0...

See Stack Overflow question Can't find the PostgreSQL client library (libpq).

查看堆栈溢出问题无法找到PostgreSQL客户端库(libpq)。

#19


2  

On FreeBSD (9.1) the necessary package is /usr/ports/database/postgresql-server* which when installed will also install the required header file that makes the gem install of "pg" fail. This answer here helped me find the solution but the difference in package names required a bit of searching.

在FreeBSD(9.1)中,必要的包是/usr/ports/database/postgresql-server*,当安装时,它还会安装所需的头文件,使gem安装“pg”失败。这个答案帮助我找到了解决方案,但是包名的不同需要一点搜索。

Hopefully this helps someone avoid a bit of head scratching when searching for the "-dev" package on a FreeBSD system!

希望这能帮助人们在FreeBSD系统中搜索“-dev”包时避免一些挠头!

#20


2  

On Debian 7.0, 64-bit (Wheezy), just run:

在Debian 7.0, 64位(Wheezy),运行:

sudo apt-get install libpq-dev

After you successfully installed libpq-dev, run:

成功安装libpq-dev后,运行:

bundle install

#21


2  

Under CentOS 6.5 (Squeeze) I created a file:

在CentOS 6.5(挤压)下,我创建了一个文件:

$ sudo touch /etc/profile.d/psql.sh

with content:

与内容:

pathmunge /usr/pgsql-9.3/bin

Note here, you should set your PostgreSQL path with the pg_config file. You can find this with the command:

注意,您应该使用pg_config文件设置您的PostgreSQL路径。您可以通过以下命令找到:

$ sudo find / -iname pg_config

Save the file:

保存文件:

$ sudo chmod +x /etc/profile.d/ruby.sh

and try to execute your command again.

并尝试再次执行您的命令。

Note: Anytime you change the Bash configuration - changing the profile.d configuration - you should reload Bash.

注意:任何时候更改Bash配置——更改配置文件。d配置-您应该重新加载Bash。

#22


2  

The location of libpq-fe.h depends on where your PostgreSQL install is (which depends on how you installed it). Use locate (http://en.wikipedia.org/wiki/Locate_%28Unix%29) to find the libpq-fe.h file on your machine. If it exists, it will be in the include directory of your PostgreSQL install.

libpq-fe的位置。h取决于您的PostgreSQL安装在哪里(这取决于您如何安装它)。使用locate (http://en.wikipedia.org/wiki/Locate_%28Unix%29)找到libpq-fe。h文件在你的机器上。如果它存在,它将在您的PostgreSQL安装的include目录中。

$ locate libpq-fe.h
/Library/PostgreSQL/9.1/include/libpq-fe.h

The bin directory, which contains pg_config, will be in the same directory as the include directory. As the error suggests, use the --with-pg-config option to install the gem:

包含pg_config的bin目录将与include目录在同一个目录中。正如错误提示的那样,使用-with-pg-config选项来安装gem:

$ gem install pg --with-pg-config="/Library/PostgreSQL/9.1/bin/pg_config"

Note that you may need to run updatedb if you have never used locate or if you haven't updated since installing PostgreSQL.

注意,如果您从未使用过位置,或者自从安装PostgreSQL之后没有更新,您可能需要运行updatedb。

#23


2  

I just had this on OSX running brew and postgres@9.4.

我刚刚在OSX上运行brew和postgres@9.4。

My fix was this:

我的修复是这样的:

CONFIGURE_ARGS="with-pg-include=/usr/local/opt/postgresql@9.4/include/" bundle install

#24


1  

For AltLinux the package postgresqlx.x-devel (in my case postgresql9.5-devel) must be installed:

对于AltLinux,包postgresqlx。x-devel(在我的例子中是postgresql9.5-devel)必须安装:

apt-get install postgresql9.5-devel

#25


1  

I solved this installing the 'postgresql-common' package. This package provides the pg_config binary which is most likely what you were missing.

我解决了这个安装“postgresql-common”包的问题。这个包提供了pg_config二进制文件,它很可能是您丢失的。

#26


1  

I was having a similar problem, and this fixed it for me:

我有一个类似的问题,这个问题解决了:

gem install do_postgres -- --with-pgsql-server-dir=/Applications/Postgres.app/Contents/MacOS --with-pgsql-server-include=/Applications/Postgres.app/Contents/MacOS/include/server

Source:

来源:

https://gist.github.com/oisin/6562181

https://gist.github.com/oisin/6562181

#27


1  

On OS X 10.9 (Mavericks), I brew-installed postgresql, and I then had to rvm reinstall my Ruby. I am happy now :)

在OS X 10.9 (Mavericks)上,我安装了postgresql,然后我不得不重新安装我的Ruby。我现在很高兴:)

#28


1  

I finally solved this problem, but not using the previously described methods.

我最终解决了这个问题,但没有使用前面描述的方法。

Using brew install postgresql, I find out that it had already been installed, but not linked.

使用brew安装postgresql,我发现它已经安装了,但没有链接。

  1. Find out where PostgreSQL is installed, and delete it,

    找出PostgreSQL的安装位置,并删除它,

  2. Then brew install postgresql again,

    然后再重新安装postgresql,

  3. brew link postgresql

    酿造postgresql的联系

  4. gem install pg

    gem安装pg

#29


1  

On Ubuntu, install the "libpq-dev" to get rid of this issue.

在Ubuntu上,安装“libpq-dev”来处理这个问题。

sudo apt-get install libpq-dev

#30


1  

For MacOS without installing PostgreSQL server:

对于不安装PostgreSQL服务器的MacOS:

brew install libpq
gem install pg -- --with-pg-config="/usr/local/Cellar/libpq/9.6.6/bin/pg_config"