CentOS 安装PostregSQL9.2 同时出现pg安装错误

错误:

Gem::Installer::ExtensionBuildError: 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.

CentOS的系统版本, 如果用yum安装的话5.x版本就会安装较低版本的PostgreSQL 所以我们要升级。不使用yum安装。

1 删除已经有的postgresql 

yum remove postgresql*

 2 安装Postgresql http://wiki.postgresql.org/wiki/YUM_Installation

下载源文件 
curl -O http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpm
安装RPM
rpm -ivh pgdg-centos91-9.1-4.noarch.rpm
列出可用的包
yum list postgres*
安装PostgreSQL server
yum install postgresql91-server

 这里你可以自己去找你要的源文件,上面的只是例子, 安装好后相关目录

默认数据库9.0以上
/var/lib/pgsql/9.2/data/
7.x/8.x
/var/lib/pgsql/data/

安装好后,初始化

service postgresql-9.2 initdb
etc/rc.d/init.d/postgresql-9.2 start
chkconfig --list 查看所有后台服务
chkconfig postgresql-9.2 on 开机启动

 开机自动启动

chkconfig postgresql-9.2 on

 最后删除文件

yum erase postgresql91*

3 安装pg

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

 参考 http://www.cnblogs.com/echovalley/archive/2012/10/12/2721716.html

解决的方式就是删除rvm 貌似是rvm的编译影响了系统的编译

mv ~/.rvm/usr/lib ~/.rvm/usr/lib_rvm  
原文地址:https://www.cnblogs.com/iosdev/p/3320664.html