无法安装 pg gem
我尝试使用 gem install pg
但它似乎不起作用。
gem install pg
给出此错误
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
C:/Ruby/bin/ruby.exe 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=C:/Ruby/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 C:/Ruby/lib/ruby/gems/1.8/gems/pg-0.10.1 for
inspection.
Results logged to C:/Ruby/lib/ruby/gems/1.8/gems/pg-0.10.1/ext/gem_make.out
I tried using gem install pg
but it doesn't seem to work.
gem install pg
gives this error
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
C:/Ruby/bin/ruby.exe 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=C:/Ruby/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 C:/Ruby/lib/ruby/gems/1.8/gems/pg-0.10.1 for
inspection.
Results logged to C:/Ruby/lib/ruby/gems/1.8/gems/pg-0.10.1/ext/gem_make.out
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(27)
我遇到了这个问题,这对我有用:
安装 postgresql-devel 包,这将解决 pg_config 丢失的问题。
I had this problem, this worked for me:
Install the postgresql-devel package, this will solve the issue of pg_config missing.
问题是 gem 依赖性,因此在安装 pg 之前请确保您已经安装了“libpq-dev”
Ubuntu 系统:
RHEL 系统:
Mac:
Issue is gem dependency so before installing pg make sure you have installed "libpq-dev"
Ubuntu systems:
RHEL systems:
Mac:
gem install pg -- --with-pg-config=/usr/pgsql-9.1/bin/pg_config
gem install pg -- --with-pg-config=/usr/pgsql-9.1/bin/pg_config
@Winfield 说的:
不仅如此,您只需要
--with-pg-config=
即可安装它。在 Mac 上
如果您还通过 Mac 上的网站捆绑包安装了 postgres,那么它将位于
/Applications/Postgres.app/Contents/Versions/9.3/bin
等位置。因此,要么在 gem 安装中传递它:
或者正确设置 PATH。由于这可能太多,暂时设置 PATH:
@Winfield said it:
More than that, you only need
--with-pg-config=
to install it.On a Mac
If, by any chance, you also installed postgres through the website bundle on mac, it will be on somewhere like
/Applications/Postgres.app/Contents/Versions/9.3/bin
.So, either you pass it on the gem install:
Or you set the PATH properly. Since that might be too much, to temporarily set the PATH:
这在我的情况下有效:
我使用:
This worked in my case:
I used:
我没有安装 postgresql,所以我只是
在 Ubuntu 12.04 上安装它。
这解决了它。
更新:
使用最新版本:
I hadn't postgresql installed, so I just installed it using
on Ubuntu 12.04.
This solved it.
Update:
Use the latest version:
在这里回答:
无法在 Windows 上安装 pg gem
Answered here:
Can't install pg gem on Windows
如果您在 Mac 上使用 Postgres.app,您可以像这样一劳永逸地解决此问题:
首先
gem uninstall pg
,然后编辑您的~/. bash_profile
或~/.zshrc
文件或等效文件并添加:然后
bundle install
和gem install pg
应该都按预期工作。If you are using Postgres.app on Mac, you may resolve this issue once and for all like this:
First
gem uninstall pg
, then edit your~/.bash_profile
or~/.zshrc
file or equivalent and add:Then
bundle install
andgem install pg
should both work as expected.在 macOS (El Capitan) 上。您可以简单地使用:
brew install postgresql
On macOS (El Capitan). You can simply use:
brew install postgresql
将 9.1 替换为系统上安装的版本。
replace the 9.1 for the version installed on your system.
卸载并重新安装
postgresql-client
libpq5
libpq-dev
然后再次安装
pg
gem,指向/usr/lib
以查找pg
库:输出(在上一个命令之后您应该看到的内容):
Gem 应该安装,然后继续正常的
bundle
安装或更新:Uninstall and then reinstall
postgresql-client
libpq5
libpq-dev
Then install the
pg
gem again pointing at/usr/lib
to find thepg
library:Output (what you should see after the previous command):
Gem should install, then continue with normal
bundle
install or update:pg gem 需要 postgresql 客户端库来绑定。此错误通常意味着它找不到您的 Postgres 库。要么您没有安装它们,要么您可能需要将 --with-pg-dir= 传递给您的 gem 安装。
The pg gem requires the postgresql client libraries to bind against. This error usually means it can't find your Postgres libraries. Either you don't have them installed or you may need to pass the --with-pg-dir= to your gem install.
对于 Mac 用户
这应该可以解决问题
For Mac Users
This should do the trick
与
ARCH
标志一起使用。这解决了您遇到的同样问题。
Use with
ARCH
flag.This resolved the same issue you are having.
我在 Linux Mint (Maya) 13 上遇到了这个问题,我通过安装 postgresql 和 postgresql-server 修复了它:
I'd this issue on Linux Mint (Maya) 13, And I fixed it by Installing postgresql and postgresql-server :
无论您运行什么操作系统,请查看“Makefile”的日志文件以了解发生了什么,而不是盲目安装东西。
在我的情况下,MAC OS,日志文件在这里:
日志表明无法创建 make 文件,原因如下:
在 mkmf.log 中,您将看到它无法找到完成构建所需的库。
运行
"brew install postgresql"
后,我可以看到所有必需的库都在那里:Regardless of what OS you are running, look at the logs file of the
"Makefile"
to see what is going on, instead of blindly installing stuff.In my case, MAC OS, the log file is here:
The logs indicated that the make file could not be created because of the following:
Inside the mkmf.log, you will see that it could not find required libraries, to finish the build.
After running
"brew install postgresql"
, I can see all required libraries being there:多年来我一直在 PG 中遇到这个恼人的问题。我创建这个要点是为了提供帮助。
以下命令始终对我有用。
要点: https://gist.github.com/sharnie/5588340cf023fb177c8d
I've been experiencing this annoying problem with PG for years. I created this gist to help.
The following command always work for me.
gist: https://gist.github.com/sharnie/5588340cf023fb177c8d
我必须在 CentOS 5.8 上执行此操作。运行
bundle install
不断导致问题,因为我无法强制它使用特定的 PG 版本。由于依赖性问题(它会删除 php、http 等),我也无法 yum 删除 postgresql postgresql-devel
解决方案?暂时混乱 $PATH 以优先选择更新 pgsql 而不是默认的:
基本上,使用上述命令,它将在 < 中的命令之前查看
/usr/pgsql-9.2/bin/pg_config
代码>/usr/bin/pg_configI had to do this on CentOS 5.8. Running
bundle install
kept causing issues since I couldn't force it to use a particular PG version.I can't
yum erase postgresql postgresql-devel
either, because of dependency issues (it would remove php, http etc)The solution? Mess $PATH temporarily to give preference to the update pgsql instead of the default one:
Basically, with the above commands, it will look at
/usr/pgsql-9.2/bin/pg_config
before the one in/usr/bin/pg_config
如果您使用 jruby 而不是 ruby,那么在安装 pg gem 时也会遇到类似的问题。相反,您需要安装适配器:
If you are using jruby instead of ruby you will have similar issues when installing the pg gem. Instead you need to install the adaptor:
在 Mac 上
brew install postgres
然后bundle install
On Mac
brew install postgres
THENbundle install
我使用的是 Linux (Pop_OS) 20.10,并使用 Ruby(和其他)的版本管理器 (
asdf
),并尝试了一百万种不同的方法对其进行排序,包括所有上面的TLDR
找到正确版本的PG安装并指向bin目录中的
pg_config
I'm on Linux (Pop_OS) 20.10 and using a version manager (
asdf
) for Ruby (and others) and after trying a million different ways to sort it including all of the aboveTLDR
Find the PG install for the right version and point to the
pg_config
in the bin directory对我来说,
bundle install
失败了(在 pg gem 上)。我做到了:然后
成功安装了pg。
For me
bundle install
was failing (on pg gem). I did:then
successfully installed pg.
你只要到这里看看你的pg版本是否支持Win32平台,然后使用这个命令安装:
gem install pg -v 0.14.1 --platform=x86-mingw32
You just go to here to see if your pg version support Win32 platform, then use this command to install:
gem install pg -v 0.14.1 --platform=x86-mingw32
如果您使用
asdf
安装postgres
,只需安装pg
gem,如下所示:If you are using
asdf
to installpostgres
, just installpg
gem like this:请注意,该库在其他一些 Linux 发行版(例如 Fedora、RHEL 等)上称为
libpq-devel
。因此,在 Fedora 上它是sudo dnf install libpq-devel
。https://unix.stackexchange.com/questions/594466/how-在 Fedora 上安装 libpq-dev
Note that this library is called
libpq-devel
on some other Linux distrubitions, like Fedora, RHEL, etc. So it'd besudo dnf install libpq-devel
on Fedora.https://unix.stackexchange.com/questions/594466/how-to-install-libpq-dev-on-fedora
如果您使用的是 MacOS,请检查
mkmf.log
以查看是否需要 xcode 许可证Run:
并在提示中输入
agree
。另外如果你已经安装了postgres。
然后
希望有帮助
If you are using MacOS, check the
mkmf.log
to see whether it requires an xcode licenceRun:
and type
agree
in the prompt.Plus if you have installed postgres.
Then
Hope it helps
就我而言,我通过brew(是的,这是我的macbook)安装了postgresql@15,如下所示
当我尝试
gem install pg
时,我看到了上面的错误。但将其添加到我的~/.bashrc
后我能够成功安装,我从
brew info postgresql@15
命令中找到了这一行In my case, I installed postgresql@15 by brew (yes, this is my macbook) like this
And when I tried
gem install pg
I saw above error. But I was able to successfully install after adding this to my~/.bashrc
I found this line from the
brew info postgresql@15
command