I am using the Ruby on Rails 3.1 pre version. I like to use PostgreSQL, but the problem is installing the pg
gem. It gives me the following error:
$ gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/u/.rvm/rubies/ruby-1.9.2-p0/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=/home/u/.rvm/rubies/ruby-1.9.2-p0/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 /home/u/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.11.0 for inspection.
Results logged to /home/u/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.11.0/ext/gem_make.out
How do I solve this problem?
I could solve this in another way. I didn't find the library on my system. Thus I installed it using an app from PostgreSQL main website. In my case (OS X) I found the file under
/Library/PostgreSQL/9.1/include/
once the installation was over. You may also have the file somewhere else depending on your system if you already have PostgreSQL installed.Thanks to this link on how to add an additional path for gem installation, I could point the gem to the lib with this command:
After that, it works, because it now knows where to find the missing library. Just replace the path with the right location for your libpq-fe.h
For CentOS 6.4,
worked well!
On OS X 10.9 (Mavericks), I
brew-installed postgresql
, and I then had torvm reinstall
my Ruby. I am happy now :)Just for the record:
Ruby on Rails 4 application in OS X with PostgresApp (in this case 0.17.1 version needed - kind of an old project):
On Debian 7.0, 64-bit (Wheezy), just run:
After you successfully installed libpq-dev, run:
I was having a similar problem, and this fixed it for me:
Source:
https://gist.github.com/oisin/6562181