无法安装 pg gem

发布于 2024-10-15 06:34:15 字数 1584 浏览 4 评论 0原文

我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(27

不寐倦长更 2024-10-22 06:34:15

我遇到了这个问题,这对我有用:

安装 postgresql-devel 包,这将解决 pg_config 丢失的问题。

sudo apt-get install libpq-dev

I had this problem, this worked for me:

Install the postgresql-devel package, this will solve the issue of pg_config missing.

sudo apt-get install libpq-dev
豆芽 2024-10-22 06:34:15

问题是 gem 依赖性,因此在安装 pg 之前请确保您已经安装了“libpq-dev”

Ubuntu 系统:

sudo apt-get install libpq-dev

RHEL 系统:

yum 安装 postgresql-devel

Mac:

酿造安装postgresql

Issue is gem dependency so before installing pg make sure you have installed "libpq-dev"

Ubuntu systems:

sudo apt-get install libpq-dev

RHEL systems:

yum install postgresql-devel

Mac:

brew install postgresql

涙—继续流 2024-10-22 06:34:15

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

十秒萌定你 2024-10-22 06:34:15

@Winfield 说的

pg gem 需要 postgresql 客户端进行绑定。此错误通常意味着它找不到您的 Postgres 库。您可能没有安装它们,或者您可能需要将 --with-pg-dir= 传递到您的 gem 安装。

不仅如此,您只需要 --with-pg-config= 即可安装它。

在 Mac 上

如果您还通过 Mac 上的网站捆绑包安装了 postgres,那么它将位于 /Applications/Postgres.app/Contents/Versions/9.3/bin 等位置。

因此,要么在 gem 安装中传递它:

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

或者正确设置 PATH。由于这可能太多,暂时设置 PATH:

export PATH=%PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin/

@Winfield said it:

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.

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:

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

Or you set the PATH properly. Since that might be too much, to temporarily set the PATH:

export PATH=%PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin/
无名指的心愿 2024-10-22 06:34:15

这在我的情况下有效:

sudo apt-get install libpq-dev

我使用:

  • Ubuntu 14.04.2 LTS
  • Ruby 2.2.2
  • Rails 4.2.1

This worked in my case:

sudo apt-get install libpq-dev

I used:

  • Ubuntu 14.04.2 LTS
  • Ruby 2.2.2
  • Rails 4.2.1
深海夜未眠 2024-10-22 06:34:15

我没有安装 postgresql,所以我只是

sudo apt-get install postgresql postgresql-server-dev-9.1

在 Ubuntu 12.04 上安装它。

这解决了它。


更新:

使用最新版本:

sudo apt-get install postgresql-9.3 postgresql-server-dev-9.3

I hadn't postgresql installed, so I just installed it using

sudo apt-get install postgresql postgresql-server-dev-9.1

on Ubuntu 12.04.

This solved it.


Update:

Use the latest version:

sudo apt-get install postgresql-9.3 postgresql-server-dev-9.3
紙鸢 2024-10-22 06:34:15

在这里回答:
无法在 Windows 上安装 pg gem

没有 Windows 本机版本
pg最新版本(0.10.0)发布
昨天,但是如果你安装了 0.9.0
应该安装没有的二进制文件
问题。

Answered here:
Can't install pg gem on Windows

There is no Windows native version of
latest release of pg (0.10.0) released
yesterday, but if you install 0.9.0 it
should install binaries without
issues.

屌丝范 2024-10-22 06:34:15

如果您在 Mac 上使用 Postgres.app,您可以像这样一劳永逸地解决此问题:

首先 gem uninstall pg,然后编辑您的 ~/. bash_profile~/.zshrc 文件或等效文件并添加:

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

然后 bundle installgem 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:

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

Then bundle install and gem install pg should both work as expected.

穿越时光隧道 2024-10-22 06:34:15

在 macOS (El Capitan) 上。您可以简单地使用:brew install postgresql

On macOS (El Capitan). You can simply use: brew install postgresql

梅窗月明清似水 2024-10-22 06:34:15
$ PATH=$PATH:/Library/PostgreSQL/9.1/bin sudo gem install pg

将 9.1 替换为系统上安装的版本。

$ PATH=$PATH:/Library/PostgreSQL/9.1/bin sudo gem install pg

replace the 9.1 for the version installed on your system.

伪心 2024-10-22 06:34:15
  • Ubuntu 20.10 (pop!_os)
  • Ruby 2.7.2
  • Rails 3.1.0
  • Postgresql 12

卸载并重新安装 postgresql-client libpq5 libpq-dev

sudo apt remove postgresql-client libpq5 libpq-dev
sudo apt install postgresql-client libpq5 libpq-dev

然后再次安装 pg gem,指向 /usr/lib 以查找 pg 库:

gem install pg  --   --with-pg-lib=/usr/lib

输出(在上一个命令之后您应该看到的内容):

Building native extensions with: '--with-pg-lib=/usr/lib'
This could take a while...
Successfully installed pg-1.2.3
Parsing documentation for pg-1.2.3
Installing ri documentation for pg-1.2.3
Done installing documentation for pg after 1 seconds
1 gem installed

Gem 应该安装,然后继续正常的 bundle 安装或更新:

bundle
bundle install
bundle update
  • Ubuntu 20.10 (pop!_os)
  • Ruby 2.7.2
  • Rails 3.1.0
  • Postgresql 12

Uninstall and then reinstall postgresql-client libpq5 libpq-dev

sudo apt remove postgresql-client libpq5 libpq-dev
sudo apt install postgresql-client libpq5 libpq-dev

Then install the pg gem again pointing at /usr/lib to find the pg library:

gem install pg  --   --with-pg-lib=/usr/lib

Output (what you should see after the previous command):

Building native extensions with: '--with-pg-lib=/usr/lib'
This could take a while...
Successfully installed pg-1.2.3
Parsing documentation for pg-1.2.3
Installing ri documentation for pg-1.2.3
Done installing documentation for pg after 1 seconds
1 gem installed

Gem should install, then continue with normal bundle install or update:

bundle
bundle install
bundle update
凉城凉梦凉人心 2024-10-22 06:34:15

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.

世界如花海般美丽 2024-10-22 06:34:15

对于 Mac 用户

PATH=$PATH:/Library/PostgreSQL/9.4/bin/ gem install pg

这应该可以解决问题

For Mac Users

PATH=$PATH:/Library/PostgreSQL/9.4/bin/ gem install pg

This should do the trick

无名指的心愿 2024-10-22 06:34:15

ARCH 标志一起使用。

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

这解决了您遇到的同样问题。

Use with ARCH flag.

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

This resolved the same issue you are having.

魂归处 2024-10-22 06:34:15

我在 Linux Mint (Maya) 13 上遇到了这个问题,我通过安装 postgresql 和 postgresql-server 修复了它:

apt-get install postgresql-9.1 

sudo apt-get install postgresql-server-dev-9.1

I'd this issue on Linux Mint (Maya) 13, And I fixed it by Installing postgresql and postgresql-server :

apt-get install postgresql-9.1 

sudo apt-get install postgresql-server-dev-9.1
北音执念 2024-10-22 06:34:15

无论您运行什么操作系统,请查看“Makefile”的日志文件以了解发生了什么,而不是盲目安装东西。

在我的情况下,MAC OS,日志文件在这里:

/Users/za/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/pg-1.0.0/mkmf.log

日志表明无法创建 make 文件,原因如下:

Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers

在 mkmf.log 中,您将看到它无法找到完成构建所需的库。

checking for pg_config... no
Can't find the 'libpq-fe.h header
blah blah

运行 "brew install postgresql" 后,我可以看到所有必需的库都在那里:

za:myapp za$ cat /Users/za/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/pg-1.0.0/mkmf.log | grep yes
find_executable: checking for pg_config... -------------------- yes
find_header: checking for libpq-fe.h... -------------------- yes
find_header: checking for libpq/libpq-fs.h... -------------------- yes
find_header: checking for pg_config_manual.h... -------------------- yes
have_library: checking for PQconnectdb() in -lpq... -------------------- yes
have_func: checking for PQsetSingleRowMode()... -------------------- yes
have_func: checking for PQconninfo()... -------------------- yes
have_func: checking for PQsslAttribute()... -------------------- yes
have_func: checking for PQencryptPasswordConn()... -------------------- yes
have_const: checking for PG_DIAG_TABLE_NAME in libpq-fe.h... -------------------- yes
have_header: checking for unistd.h... -------------------- yes
have_header: checking for inttypes.h... -------------------- yes
checking for C99 variable length arrays... -------------------- yes

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:

/Users/za/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/pg-1.0.0/mkmf.log

The logs indicated that the make file could not be created because of the following:

Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers

Inside the mkmf.log, you will see that it could not find required libraries, to finish the build.

checking for pg_config... no
Can't find the 'libpq-fe.h header
blah blah

After running "brew install postgresql", I can see all required libraries being there:

za:myapp za$ cat /Users/za/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/pg-1.0.0/mkmf.log | grep yes
find_executable: checking for pg_config... -------------------- yes
find_header: checking for libpq-fe.h... -------------------- yes
find_header: checking for libpq/libpq-fs.h... -------------------- yes
find_header: checking for pg_config_manual.h... -------------------- yes
have_library: checking for PQconnectdb() in -lpq... -------------------- yes
have_func: checking for PQsetSingleRowMode()... -------------------- yes
have_func: checking for PQconninfo()... -------------------- yes
have_func: checking for PQsslAttribute()... -------------------- yes
have_func: checking for PQencryptPasswordConn()... -------------------- yes
have_const: checking for PG_DIAG_TABLE_NAME in libpq-fe.h... -------------------- yes
have_header: checking for unistd.h... -------------------- yes
have_header: checking for inttypes.h... -------------------- yes
checking for C99 variable length arrays... -------------------- yes
清引 2024-10-22 06:34:15

多年来我一直在 PG 中遇到这个恼人的问题。我创建这个要点是为了提供帮助。

以下命令始终对我有用。

# Substitute Postgres.app/Contents/Versions/9.5 with appropriate version number
sudo ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.5/bin/pg_config

要点: 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.

# Substitute Postgres.app/Contents/Versions/9.5 with appropriate version number
sudo ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.5/bin/pg_config

gist: https://gist.github.com/sharnie/5588340cf023fb177c8d

心奴独伤 2024-10-22 06:34:15

我必须在 CentOS 5.8 上执行此操作。运行 bundle install 不断导致问题,因为我无法强制它使用特定的 PG 版本。

由于依赖性问题(它会删除 php、http 等),我也无法 yum 删除 postgresql postgresql-devel

解决方案?暂时混乱 $PATH 以优先选择更新 pgsql 而不是默认的:

export PATH=/usr/pgsql-9.2/bin:$PATH
bundle install

基本上,使用上述命令,它将在 < 中的命令之前查看 /usr/pgsql-9.2/bin/pg_config代码>/usr/bin/pg_config

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

export PATH=/usr/pgsql-9.2/bin:$PATH
bundle install

Basically, with the above commands, it will look at /usr/pgsql-9.2/bin/pg_config before the one in /usr/bin/pg_config

埋情葬爱 2024-10-22 06:34:15

如果您使用 jruby 而不是 ruby​​,那么在安装 pg gem 时也会遇到类似的问题。相反,您需要安装适配器:

gem 'activerecord-jdbcpostgresql-adapter'

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:

gem 'activerecord-jdbcpostgresql-adapter'
迟月 2024-10-22 06:34:15

在 Mac 上 brew install postgres 然后 bundle install

On Mac brew install postgres THEN bundle install

甜是你 2024-10-22 06:34:15

我使用的是 Linux (Pop_OS) 20.10,并使用 Ruby(和其他)的版本管理器 (asdf),并尝试了一百万种不同的方法对其进行排序,包括所有上面的

TLDR

gem install pg -v '1.2.3' -- --with-pg-config='/home/username/.asdf/installs/postgres/12.6/bin/pg_config'

找到正确版本的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 above

TLDR

gem install pg -v '1.2.3' -- --with-pg-config='/home/username/.asdf/installs/postgres/12.6/bin/pg_config'

Find the PG install for the right version and point to the pg_config in the bin directory

九公里浅绿 2024-10-22 06:34:15

对我来说,bundle install 失败了(在 pg gem 上)。我做到了:

brew install libpq
brew link --force libpq

然后

bundle install

成功安装了pg。

For me bundle install was failing (on pg gem). I did:

brew install libpq
brew link --force libpq

then

bundle install

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

与他有关 2024-10-22 06:34:15

如果您使用 asdf 安装 postgres,只需安装 pg gem,如下所示:

asdf global postgres <version>
gem install pg

If you are using asdf to install postgres, just install pg gem like this:

asdf global postgres <version>
gem install pg
贩梦商人 2024-10-22 06:34:15

请注意,该库在其他一些 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 be sudo dnf install libpq-devel on Fedora.

https://unix.stackexchange.com/questions/594466/how-to-install-libpq-dev-on-fedora

£烟消云散 2024-10-22 06:34:15

如果您使用的是 MacOS,请检查 mkmf.log 以查看是否需要 xcode 许可证

Run:

sudo xcodebuild -license

并在提示中输入 agree

另外如果你已经安装了postgres。

where pg_config

然后

gem install pg:1.4.5 -- --with-pg-config='/usr/local/opt/libpq/bin/pg_config'

希望有帮助

If you are using MacOS, check the mkmf.log to see whether it requires an xcode licence

Run:

sudo xcodebuild -license

and type agree in the prompt.

Plus if you have installed postgres.

where pg_config

Then

gem install pg:1.4.5 -- --with-pg-config='/usr/local/opt/libpq/bin/pg_config'

Hope it helps

凉城凉梦凉人心 2024-10-22 06:34:15

就我而言,我通过brew(是的,这是我的macbook)安装了postgresql@15,如下所示

brew install postgresql@15
brew services start postgresql@15

当我尝试gem install pg时,我看到了上面的错误。但将其添加到我的 ~/.bashrc 后我能够成功安装,

export PATH="/opt/homebrew/opt/postgresql@15/bin:$PATH"

我从 brew info postgresql@15 命令中找到了这一行

In my case, I installed postgresql@15 by brew (yes, this is my macbook) like this

brew install postgresql@15
brew services start postgresql@15

And when I tried gem install pg I saw above error. But I was able to successfully install after adding this to my ~/.bashrc

export PATH="/opt/homebrew/opt/postgresql@15/bin:$PATH"

I found this line from the brew info postgresql@15 command

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文