Ruby on rails 无法安装pg gem

Ruby on rails 无法安装pg gem,ruby-on-rails,ruby,rubygems,installation,Ruby On Rails,Ruby,Rubygems,Installation,我尝试使用gem安装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 e

我尝试使用
gem安装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
答复如下:

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


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

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

安装postgresql开发包,这将解决pg_配置丢失的问题

sudo apt-get install libpq-dev
gem安装pg--with pg config=/usr/pgsql-9.1/bin/pg_config

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

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

我没有安装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

我必须在CentOS 5.8上完成这项工作。运行
bundle install
会不断导致问题,因为我无法强制它使用特定的PG版本

我也无法
yum擦除postgresql-postgresql-devel
,因为存在依赖性问题(它会删除php、http等)

解决方案是什么?将$PATH临时更改为update pgsql而不是默认值:

export PATH=/usr/pgsql-9.2/bin:$PATH
bundle install
基本上,使用上述命令,它会先查看
/usr/pgsql-9.2/bin/pg_config
,然后再查看
/usr/bin/pg_config

中的命令。您只需查看您的pg版本是否支持Win32平台,然后使用此命令安装:

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

gem install pg-v 0.14.1--platform=x86-mingw32

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

apt-get install postgresql-9.1 

sudo apt-get install postgresql-server-dev-9.1
@温菲尔德:


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

除此之外,您只需使用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
你。由于这可能太多,要临时设置路径:

export PATH=%PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin/
适用于Mac用户

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

这应该可以解决gem依赖性的问题,因此在安装pg之前,请确保您已经安装了“libpq-dev”

Ubuntu系统:

sudo apt get安装libpq dev

RHEL系统:

yum安装postgresql-devel

Mac:

brew安装postgresql


这在我的情况下起了作用:

sudo apt-get install libpq-dev
我用过:

  • Ubuntu 14.04.2 LTS
  • Ruby 2.2.2
  • 轨道4.2.1

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

gem 'activerecord-jdbcpostgresql-adapter'

如果您在Mac上使用Postgres.app,您可以一次性解决此问题,如下所示:

首先
gem卸载pg
,然后编辑您的
~/.bash_配置文件
~/.zshrc
文件或等效文件,并添加:

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

然后
捆绑安装
gem安装pg
应该都能按预期工作。

在macOS(El Capitan)上。您只需使用:
brew安装postgresql
ARCH
标志一起使用即可

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

这解决了您现在遇到的相同问题。

在Mac上安装brew postgres然后
捆绑安装
无论您运行的是什么操作系统,都要查看
“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安装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

多年来,我一直在经历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
要点:

  • Ubuntu 20.10(pop!\u操作系统)
  • Ruby 2.7.2
  • Rails 3.1.0
  • Postgresql 12
卸载并重新安装
postgresql客户端
libpq5
libpq-dev

sudo apt删除postgresql客户端libpq5 libpq dev
sudo apt安装postgresql客户端libpq5 libpq dev
然后再次安装
pg
gem,指向
/usr/lib
查找
pg
库:

gem安装pg--with pg lib=/usr/lib
输出(在上一个命令之后应该看到的内容):

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

bundle
捆绑安装
包更新
我在Linux(Pop_OS)20.10上,使用Ruby(和其他)的版本管理器(
asdf
),尝试了一百万种不同的排序方法,包括以上所有方法

TLDR


找到正确版本的PG安装,并指向bin目录中的
PG_config
apt get install libpq dev
为我工作。感谢您的提示。对于我在ubuntu LTS 10Confirmation上安装postgresql-server-dev-8.4,请参见:“在ubuntu上,/usr/bin/pg_config由libpq dev软件包提供。”@Fivell在这里给出了答案,但如果您安装了自制软件,
brew安装postgresql
将为您提供所需的软件包。@请在mac上尝试
brew安装postgresql
。这对我在mac上的工作很有帮助,有人知道默认路径是什么吗
gem install pg -v '1.2.3' -- --with-pg-config='/home/username/.asdf/installs/postgres/12.6/bin/pg_config'