无法安装pg gem

时间:2011-01-28 10:19:28

标签: ruby-on-rails ruby rubygems installation

我尝试使用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

22 个答案:

答案 0 :(得分:364)

我有这个问题,这对我有用:

安装postgresql-devel包,这样可以解决pg_config缺失的问题。

sudo apt-get install libpq-dev

答案 1 :(得分:72)

问题是gem依赖所以在安装pg之前确保你已经安装了" libpq-dev"

Ubuntu系统:

  

sudo apt-get install libpq-dev

RHEL系统:

  

yum install postgresql-devel

Mac:

  

brew install postgresql

答案 2 :(得分:58)

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

答案 3 :(得分:34)

@Winfield said it

  

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

更重要的是,您只需要--with-pg-config=来安装它。

在Mac上

如果您有任何机会通过Mac上的网站捆绑软件安装postgres,它将位于/Applications/Postgres.app/Contents/Versions/9.3/bin之类的地方。

所以,要么你在gem install上传递它:

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

set the PATH properly。由于这可能太多,暂时设置PATH:

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

答案 4 :(得分:24)

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

答案 5 :(得分:16)

在我的情况下工作,我使用ubuntu 14.04.2 LTS

  

sudo apt-get install libpq-dev

我使用

  

Ruby 2.2.2   &安培;   Rails 4.2.1

答案 6 :(得分:14)

在这里回答: Can't install pg gem on Windows

  

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

答案 7 :(得分:10)

如果您在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应该按预期工作。

答案 8 :(得分:9)

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

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

答案 9 :(得分:5)

在Mac OS(El Capitano)上。您只需使用:brew install postgresql

即可

答案 10 :(得分:3)

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

答案 11 :(得分:3)

ARCH标志一起使用。

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

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

答案 12 :(得分:2)

适用于Mac用户

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

这应该可以解决问题

答案 13 :(得分:2)

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

apt-get install postgresql-9.1 

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

答案 14 :(得分:2)

无论您运行的操作系统是什么,请查看"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

答案 15 :(得分:2)

  • 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

答案 16 :(得分:1)

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

gem 'activerecord-jdbcpostgresql-adapter'

答案 17 :(得分:1)

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

我也不能yum erase postgresql postgresql-devel,因为依赖问题(它会删除php,http等)

解决方案? Mess $ PATH暂时优先使用更新pgsql而不是默认值:

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

基本上,使用上述命令,它会在/usr/pgsql-9.2/bin/pg_config

中的/usr/bin/pg_config之前查看{{1}}

答案 18 :(得分:1)

在Mac上brew install postgres然后bundle install

答案 19 :(得分:1)

多年来我一直在经历这个恼人的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

答案 20 :(得分:0)

您只需转到here查看您的pg版本是否支持Win32平台,然后使用此命令进行安装:

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

答案 21 :(得分:0)

我在 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

相关问题