无法安装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
    
已邀请:
这里回答: 无法在Windows上安装pg gem   没有Windows原生版本   最新发布的pg(0.10.0)发布   昨天,但如果你安装0.9.0它   应该没有安装二进制文件   的问题。     
我有这个问题,这对我有用: 安装postgresql-devel包,这将解决pg_config缺失的问题。
sudo apt-get install libpq-dev
    
问题是gem依赖所以在安装pg之前确保你已经安装了“libpq-dev” Ubuntu系统:   sudo apt-get install libpq-dev RHEL系统:   yum install postgresql-devel 苹果电脑:   brew安装postgresql     
gem install pg -- --with-pg-config=/usr/pgsql-9.1/bin/pg_config
    
@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/
    
我没有安装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
    
在我的情况下工作,我使用ubuntu 14.04.2 LTS   sudo apt-get install libpq-dev 我用   Ruby 2.2.2   &安培;   Rails 4.2.1     
如果您在Mac上使用Postgres.app,您可以一劳永逸地解决此问题,如下所示: 首先
gem uninstall pg
,然后编辑你的
~/.bash_profile
~/.zshrc
文件或同等文件并添加:
# PostgreSQL bin path
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
那么
bundle install
gem install pg
都应该按预期工作。     
$ PATH=$PATH:/Library/PostgreSQL/9.1/bin sudo gem install pg
将9.1替换为系统上安装的版本。     
在Mac OS(El Capitano)上。你可以简单地使用:
brew install postgresql
    
pg gem需要postgresql客户端库进行绑定。此错误通常意味着它无法找到您的Postgres库。要么您没有安装它们,要么您可能需要将--with-pg-dir =传递给您的gem安装。     
ARCH
标志一起使用。
sudo env ARCHFLAGS="-arch x86_64" gem install pg
这解决了您遇到的同样问题。     
我在Linux Mint(Maya)13上遇到过这个问题,我通过安装postgresql和postgresql-server修复了它:
apt-get install postgresql-9.1 

sudo apt-get install postgresql-server-dev-9.1
    
对于Mac用户
PATH=$PATH:/Library/PostgreSQL/9.4/bin/ gem install pg
这应该可以解决问题     
无论您运行的操作系统是什么,请查看
"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
    
我必须在CentOS 5.8上这样做。运行
bundle install
一直导致问题,因为我不能强迫它使用特定的PG版本。 我也不能
yum erase postgresql postgresql-devel
,因为依赖问题(它会删除php,http等) 解决方案? Mess $ PATH暂时优先使用更新pgsql而不是默认值:
export PATH=/usr/pgsql-9.2/bin:$PATH
bundle install
基本上,使用上面的命令,它将在
/usr/bin/pg_config
之前看到
/usr/pgsql-9.2/bin/pg_config
    
如果您使用的是jruby而不是ruby,那么在安装pg gem时会遇到类似的问题。相反,您需要安装适配器:
gem 'activerecord-jdbcpostgresql-adapter'
    
在Mac
brew install postgres
那么
bundle install
    
你只是到这里看看你的pg版本是否支持Win32平台,然后用这个命令来安装: gem install pg -v 0.14.1 --platform = x86-mingw32     
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     

要回复问题请先登录注册