Ruby-on-rails 无法安装 pg gem
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4827092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
unable to install pg gem
提问by Rohit
I tried using gem install pgbut it doesn't seem to work.
我尝试使用gem install pg但它似乎不起作用。
gem install pggives this error
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
采纳答案by Nikita Barsukov
Answered here: Can't install pg gem on Windows
在这里回答: 无法在 Windows 上安装 pg gem
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.
昨天发布的最新版本的 pg (0.10.0) 没有 Windows 原生版本,但是如果您安装 0.9.0,它应该可以毫无问题地安装二进制文件。
回答by Devaroop
I had this problem, this worked for me:
我遇到了这个问题,这对我有用:
Install the postgresql-devel package, this will solve the issue of pg_config missing.
安装 postgresql-devel 包,这将解决 pg_config 丢失的问题。
sudo apt-get install libpq-dev
回答by Mahattam
Issue is gem dependency so before installing pg make sure you have installed "libpq-dev"
问题是 gem 依赖,所以在安装 pg 之前确保你已经安装了“libpq-dev”
Ubuntu systems:
Ubuntu系统:
sudo apt-get install libpq-dev
须藤 apt-get 安装 libpq-dev
RHEL systems:
RHEL系统:
yum install postgresql-devel
yum 安装 postgresql-devel
Mac:
苹果电脑:
brew install postgresql
brew 安装 postgresql
回答by Flaviu
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
回答by cregox
@Winfield said it:
@Winfield说过:
The pg gem requires the postgresql client librariesto 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.
pg gem 需要绑定postgresql 客户端库。此错误通常意味着它找不到您的 Postgres 库。要么您没有安装它们,要么您可能需要将 传递
--with-pg-dir=给您的 gem 安装。
More than that, you only need --with-pg-config=to install it.
不仅如此,您只需要--with-pg-config=安装它。
On a Mac
在 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.
如果有任何机会,您还通过 mac 上的网站包安装了 postgres,它将位于类似/Applications/Postgres.app/Contents/Versions/9.3/bin.
So, either you pass it on the gem install:
所以,要么你把它传递给 gem 安装:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
Oryou set the PATH properly. Since that might be too much, to temporarily set the PATH:
或者您正确设置了 PATH。由于这可能太多了,暂时设置PATH:
export PATH=%PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin/
回答by Lasse Skindstad Ebert
I hadn't postgresql installed, so I just installed it using
我没有安装 postgresql,所以我只是使用
sudo apt-get install postgresql postgresql-server-dev-9.1
on Ubuntu 12.04.
在 Ubuntu 12.04 上。
This solved it.
这解决了它。
Update:
更新:
Use the latest version:
使用最新版本:
sudo apt-get install postgresql-9.3 postgresql-server-dev-9.3
回答by Zainal
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
- Ubuntu 14.04.2 LTS
- 红宝石 2.2.2
- 导轨 4.2.1
回答by Darme
If you are using Postgres.appon Mac, you may resolve this issue once and for all like this:
如果你在 Mac上使用Postgres.app,你可以像这样一劳永逸地解决这个问题:
First gem uninstall pg, then edit your ~/.bash_profileor ~/.zshrcfile or equivalent and add:
首先gem uninstall pg,然后编辑您的~/.bash_profile或~/.zshrc文件或等效文件并添加:
# PostgreSQL bin path
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
Then bundle installand gem install pgshould both work as expected.
然后bundle install和gem install pg都应该按预期工作。
回答by jstnno
$ PATH=$PATH:/Library/PostgreSQL/9.1/bin sudo gem install pg
replace the 9.1 for the version installed on your system.
将 9.1 替换为您系统上安装的版本。
回答by Jones Agyemang
On Mac OS (El Capitano). You can simply use: brew install postgresql
在 Mac OS (El Capitano) 上。您可以简单地使用:brew install postgresql

