Ruby-on-rails PostgreSQL gem pg 无法安装

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13702417/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:08:01  来源:igfitidea点击:

PostgreSQL gem pg was unable to install

ruby-on-railsruby

提问by Pavan Kumar

My DB is PostgreSQL.I am on CENTOS.... While installing the pg gem I received the following error. I reinstalled to clear my YAML problem also, which didn't work, but it is just a warning. My main problem is the installation of the pg gem:

我的数据库是 PostgreSQL。我在 CENTOS 上......在安装 pg gem 时我收到以下错误。我也重新安装以清除我的 YAML 问题,但没有用,但这只是一个警告。我的主要问题是 pg gem 的安装:

[root@vdimc04 ~]# gem install pg
/usr/local/lib/ruby/1.9.1/yaml.rb:56:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

        /usr/local/bin/ruby 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=/usr/local/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 /usr/local/lib/ruby/gems/1.9.1/gems/pg-0.14.1 for inspection.
Results logged to /usr/local/lib/ruby/gems/1.9.1/gems/pg-0.14.1/ext/gem_make.out

I also tried with the following command, but to no use:

我也尝试过以下命令,但没有用:

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

回答by Prem

I got the same error on Centos. By googling I found two commands to use:

我在 Centos 上遇到了同样的错误。通过谷歌搜索,我发现了两个要使用的命令:

  1. yum install postgresql-libs-- It gave me message saying, its already installed.
  2. yum install postgresql-devel-- It solved my error related to pg_configfor installing the 'pg' .gem.
  1. yum install postgresql-libs-- 它给我消息说,它已经安装了。
  2. yum install postgresql-devel-- 它解决了我与pg_config安装“pg”.gem相关的错误。

Hope it helps :)

希望能帮助到你 :)

apos wrote: on Ubuntu 14.04 install:

apos 写道: 在 Ubuntu 14.04 上安装:

  1. apt-get install postgresql-server-dev-9.3 libpq-dev
  1. apt-get install postgresql-server-dev-9.3 libpq-dev

回答by Alistair A. Israel

Here's my recipe for getting PostgreSQL, RVM, Ruby, Rails all up and running on CentOS

这是我在 CentOS 上启动并运行 PostgreSQL、RVM、Ruby、Rails 的秘诀

PostgreSQL

PostgreSQL

First, follow the instructions on http://wiki.postgresql.org/wiki/YUM_Installationto get PostgreSQL installed:

首先,按照http://wiki.postgresql.org/wiki/YUM_Installation上的说明安装 PostgreSQL:

sudo vi /etc/yum.repos.d/CentOS-Base.repo

sudo vi /etc/yum.repos.d/CentOS-Base.repo

[base]
exclude=postgresql*

[updates]
exclude=postgresql*

Get the latest PGDG RPM file (for your platform/architecture), for example:

获取最新的 PGDG RPM 文件(适用于您的平台/架构),例如:

curl -O http://yum.postgresql.org/9.2/redhat/rhel-latest-x86_64/pgdg-redhat92-9.2-7.noarch.rpm

Then

然后

sudo rpm -ivh pgdg-redhat92-9.2-7.noarch.rpm
sudo yum install -y postgresql92-server postgresql92-devel

Initialize the database:

初始化数据库:

sudo service postgresql-9.2 initdb

Configure /var/lib/pgsql/9.2/data/postgresql.confand /var/lib/pgsql/9.2/data/pg_hba.confas needed.

配置/var/lib/pgsql/9.2/data/postgresql.conf/var/lib/pgsql/9.2/data/pg_hba.conf需要。

Start PostgreSQL server:

启动 PostgreSQL 服务器:

sudo service postgresql-9.2 start

RVM

虚拟机

sudo yum -y groupinstall "Development Tools"
sudo yum -y install zlib zlib-devel sqlite-devel httpd curl-devel httpd-devel apr-devel apr-util-devel mlocate man libxml2-devel libxslt-devel libffi-devel readline-devel

Note, NOTas root:

注意,不是root:

\curl -L get.rvm.io | sudo bash -s stable

Logout and back on. Afterwards, which rvmshould reply with /usr/local/rvm/bin/rvmand type rvm|head -1should say rvm is a function.

注销并重新启动。此后,which rvm应与答复/usr/local/rvm/bin/rvmtype rvm|head -1应该说的rvm is a function

Ruby + Rails

红宝石 + 导轨

rvm install 1.9.3 --with-openssl-dir=/usr
rvm use 1.9.3 --default
gem install rake
gem install rails

PostgreSQL gem

PostgreSQL 宝石

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

The --with-pg-configis somehow needed with my latest installation of CentOS, otherwise, gem install pgcan't find pg_config. YMMV, but if you follow all the above to the letter (which I've done enough times in the past few months) just let me know if anything trips you up.

--with-pg-config以某种方式需要与我的最新的安装CentOS的,否则,gem install pg无法找到pg_config。YMMV,但是如果您按照上述所有内容(我在过去几个月中已经完成了足够多的次数),请告诉我是否有任何问题。

回答by oFca

try installing libpq package by doing:

尝试通过执行以下操作安装 libpq 包:

sudo apt-get install libpq-dev

That package helps with pg gem and you should be fine after that :)

那个包对 pg gem 有帮助,之后你应该没问题:)

回答by selaromi

Try This, the answer is not mine but it worked for me. Remember to point to where your Postgres.app application is:

试试这个,答案不是我的,但对我有用。请记住指出您的 Postgres.app 应用程序所在的位置:

bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config

Then do

然后做

bundle update
bundle install

回答by vijikumar

$ sudo apt-get install libpq-dev
$ sudo apt-get install libdbd-pg-ruby1.8

then:

然后:

$ sudo apt-get install pg  

for CentOS please read the below link..

对于 CentOS,请阅读以下链接。

http://wiki.postgresql.org/wiki/YUM_Installation

http://wiki.postgresql.org/wiki/YUM_Installation

To install pg in centOS

在centOS中安装pg

run this commands

bundle config build.pg 

gem install pg -v '0.12.0'

回答by chinnabujji

Try to install postgresql server and corresponding libraries. Then install the pg gem. Then it will work for u

尝试安装 postgresql 服务器和相应的库。然后安装 pg gem。然后它会为你工作

回答by hiveer

I got the same problem and I tried to install all dependencies, but all is useless. In the end, I had a try to use PostgreSQL9.3, not PostgreSQL9.4, and everything is fine.

我遇到了同样的问题,我尝试安装所有依赖项,但都是无用的。最后,我尝试使用PostgreSQL9.3,而不是PostgreSQL9.4,一切都很好。

回答by kai_onthereal

Using AWS Cloud 9 Linux:

使用 AWS Cloud 9 Linux:

sudo yum install postgresql-libs

sudo yum install postgresql-libs

then:

然后:

sudo yum install postgresql-devel

sudo yum install postgresql-devel

then:

然后:

gem update --system

gem update --system

if needed, then:

如果需要,那么:

gem install bundler(Bundler 2.0)

gem install bundler(捆绑器 2.0)

then:

然后:

bundle install

bundle install

回答by Pavan Kumar

My problem is before pg gem was already installed.. but it is not loading to bundle.. Now the solution is: when we are declaring a new application like 'rails new Demo' we have to include

我的问题是在 pg gem 已经安装之前..但它没有加载到捆绑包..现在的解决方案是:当我们声明一个像“rails new Demo”这样的新应用程序时,我们必须包括

'--database=postgresql'. so now the total command is: 'rails new Demo --database=postgresql'

'--database=postgresql'。所以现在总命令是:'rails new Demo --database=postgresql'

Then the pg gem file will gets to bundle..

然后 pg gem 文件将被打包。

In bundle only one gem will gets store . either pg gem or sqlite3 gem..

在 bundle 中,只有一颗 gem 会得到 store 。无论是 pg gem 还是 sqlite3 gem..

Now edit the database.yml file accordingly.. thats it

现在相应地编辑 database.yml 文件..就是这样

回答by Gowri Naidu R

First install

首先安装

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

Next install

下次安装

sudo apt-get install libpq-dev

Then install gem install pg

然后安装 gem install pg