尝试安装 pg gem 时找不到‘libpq-fe.h 标头

问:

我正在使用 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

我该如何解决这个问题?

答1:

huntsbot.com汇聚了国内外优秀的初创产品创意,可按收入、分类等筛选,希望这些产品与实践经验能给您带来灵感。

在 Ubuntu 中,标头似乎是 libpq-dev package 的一部分(至少在以下 Ubuntu 版本中:11.04(Natty Narwhal)、10.04(Lucid Lynx)、11.10(Oneiric Ocelot)、12.04 (Precise Pangolin)、14.04 (Trusty Tahr) 和 18.04 (Bionic Beaver)):

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

因此,请尝试为您的操作系统安装 libpq-dev 或其等效项:

对于 Ubuntu/Debian 系统:sudo apt-get install libpq-dev

在 Red Hat Linux (RHEL) 系统上: yum install postgresql-devel

对于 Mac Homebrew: brew install postgresql

对于 Mac MacPorts PostgreSQL: gem install pg – --with-pg-config=/opt/local/lib/postgresql[版本号]/bin/pg_config

对于 OpenSuse:postgresql-devel 中的 zypper

对于 ArchLinux:pacman -S postgresql-libs

在 ubuntu 11.04 durrantm@castleLinux2011:~/Dropbox_not_syncd/webs/3/linker$ gem install libpq-dev ERROR: Could not find a valid gem 'libpq-dev' (>= 0) in any repository durrantm@castleLinux2011:~/Dropbox_not_syncd/webs/3/linker$ 上对我不起作用

如果您需要安装 javascript 库... gem install 'execjs' 和 gem install 'therubyracer'

请修改您的答案以包括 apt-get install postgres-server-dev-{pg.version} 您的答案不再适用于 Ubuntu 14.04 上的 postgresql 9.4 请参阅:stackoverflow.com/a/28837453/75194

当我执行命令:sudo apt-get install libpq-dev 时,我得到一个响应 - “无法找到包”。所以我执行sudo apt-get update,然后执行“sudo apt-get install libpq-dev”。终于成功安装了。

这对我有用,我已经安装了 Postgres,我只需要执行 sudo apt-get install libpq-dev 然后 bundle install 并且错误消失了。谢谢

答2:

huntsbot.com – 高效赚钱,自由工作

在 macOS(之前为 Mac OS X 和 OS X)上,使用 Homebrew 安装正确的标头:

brew install postgresql

然后运行

gem install pg

应该管用。

或者,您可以 brew install libpq 并导出正确的 PATH 和 PKG_CONFIG_PATH,而不是安装整个 postgresql,如“注意事项”部分中所述

如果您还使用 Postgres.app,这会导致任何问题吗?

对我来说,运行 brew install postgressql 后我运行 ARCHFLAGS="-arch x86_64" gem install pg 并且工作正常。

或者,只需在 mac OSX 上运行 brew install libpqxx 就足够了

@RicardoSaporta libpqxx 将 postgresql 安装为依赖项,因此它与 brew install postgresql 基本相同

您可以按照“注意事项”部分中的说明brew install libpq 并导出正确的 PATH 和 PKG_CONFIG_PATH,而不是安装整个 postgresql。

答3:

huntsbot.com – 高效赚钱,自由工作

我也试过做 gem install libpq-dev,但我收到了这个错误:

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

但是我发现使用 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

然后我能够做到

gem install pg

没有问题。

没错,Ruby pg gem 包装了 Ubuntu/Debian/... libpq-dev 软件包附带的常用 PostgreSQL C 库。

答4:

打造属于自己的副业,开启自由职业之旅,从huntsbot.com开始!

我可以用另一种方式解决这个问题。我没有在我的系统上找到该库。因此,我使用 PostgreSQL 主网站上的应用程序安装了它。就我而言(OS X),我在安装结束后在 /Library/PostgreSQL/9.1/include/ 下找到了该文件。如果您已经安装了 PostgreSQL,您可能还会在其他地方保存该文件,具体取决于您的系统。

感谢 how to add an additional path for gem installation 上的此链接,我可以使用以下命令将 gem 指向库:

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

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

大卫的解决方案对我有用。我将 libpq-fe.h 跟踪到“/Applications/Postgres.app/Contents/Versions/9.3/include”并使用带有所述路径的导出命令,然后是“gem install pg”和成功安装的 gem。

谢谢你,为我工作,使用:export CONFIGURE_ARGS="with-pg-include=/usr/local/Cellar/postgresql/9.3.1/include/"

在 CentOS 6 上使用 Postgresql 9.3 我通过将 pg_* 脚本符号链接到 $PATH 来解决这个问题,如下所示:ln -s /usr/pgsql-9.3/bin/p* /usr/local/bin。我像这样安装了 postgres 9.3:yum install http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm && yum install postgresql93 postgresql93-contrib postgresql93-server postgresql93-devel

你也可以写成gem install pg -- with-pg-include=/Library/PostgreSQL/9.1/include/

更好的是,使用 export CONFIGURE_ARGS="with-pg-config=/path/to/postgres/bin/pg_config"。将调用 pg_config 可执行文件以获取所有必需的编译器和链接器选项 — 您可以自己运行它来查看它们。

答5:

HuntsBot周刊–不定时分享成功产品案例,学习他们如何成功建立自己的副业–huntsbot.com

找不到 libpq-fe.h 标头

我在运行以下命令的 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

或者,您可以将捆绑器配置为始终使用这些选项安装 pg(有助于在部署环境中运行捆绑器),

捆绑配置 build.pg --with-pg-config=/usr/pgsql-9.4/bin/pg_config

很有帮助,谢谢。只需添加有关捆绑配置的注释...您必须在以将运行后续捆绑命令的用户身份登录时运行此命令。 bundler 配置存储在 ~/.bundle/config 中,因此如果您在以 root 身份登录时运行 bundle config 将找不到它,但是 bundler 正在由(例如使用 capistrano)“部署”用户运行。

bundle config build.pg --with-pg-config=/usr/pgsql-9.4/bin/pg_config 在 Centos 7 上为我解决 i

bundle config build.pg --with-pg-config=/usr/pgsql-10/bin/pg_config 如果你使用的是 postgresql10

对于 postgres 12 及更高版本,我必须做 yum install libpq5-devel

答6:

huntsbot.com聚合了超过10+全球外包任务平台的外包需求,寻找外包任务与机会变的简单与高效。

对于 CentOS 6.4,

yum install postgresql-devel
gem install pg

工作得很好!

huntsbot.com提供全网独家一站式外包任务、远程工作、创意产品分享与订阅服务!

使用 macport,sudo port install postgresql-devel。

答7:

HuntsBot周刊–不定时分享成功产品案例,学习他们如何成功建立自己的副业–huntsbot.com

仅作记录:

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

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

如果您使用出色的 Postgres.app,效果会很好。对于 Postgres 10,我使用了路径 /Applications/Postgres.app/Contents/Versions/10/bin/pg_config

答8:

huntsbot.com精选全球7大洲远程工作机会,涵盖各领域,帮助想要远程工作的数字游民们能更精准、更高效的找到对方。

在 Mac OS X 上运行如下:

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

/path/to/pg_config 是 pg_config 的路径

赞成。我通过 EnterpriseDB 的 grapihcal installer 安装了 Postgresql。然后我需要通过sudo find / -name "pg_config"找出pg-config路径,然后使用我刚刚找到的路径执行gem install pg -- --with-pg-config=/Library/PostgreSQL/9.4/bin/pg_config。

答9:

打造属于自己的副业,开启自由职业之旅,从huntsbot.com开始!

就我而言,它是包 postgresql-server-dev-8.4(我在 Ubuntu 11.04 (Natty Narwhal),64 位)。

答10:

huntsbot.com高效搞钱,一站式跟进超10+任务平台外包需求

对于没有安装 PostgreSQL 服务器的 MacOS:

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

答11:

保持自己快人一步,享受全网独家提供的一站式外包任务、远程工作、创意产品订阅服务–huntsbot.com

这只是缺少 libpq-fe.h 的问题

在 ubuntu 上,我们只需要运行:sudo apt-get install libpq-dev

上面的命令将安装一个新的包 libpq-dev,之后您可以再次执行 bundle install 以恢复您的包安装。

像魅力一样工作! sudo apt-get install libpq-dev && cd project-directory && bundle install 。

原文链接:https://www.huntsbot.com/qa/0AP3/cant-find-the-libpq-fe-h-header-when-trying-to-install-pg-gem?lang=zh_CN&from=csdn

huntsbot.com – 高效赚钱,自由工作

猜你喜欢

转载自blog.csdn.net/kalman2019/article/details/128712268