Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pg gem install fails, cannot find libpq-fe.h header

Whenever I run bundle install on my VPS (CentOS Linux release 7.0.1406 (Core)) I get an error when installing the pg gem.

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.

I can install pg standalone with: gem install pg -- --with-pg-config=/usr/pgsql-9.4/bin/pg_config and the issue is resolved.

So I added a capistrano taskto create a ./bundle/config for the deploy with the build.pg key set with the path to pg_config on my VPS. In the Capistrano config/deploy.rb this is invoked before bundler:install.

desc "Create bundle config"
task :prepare_bundle_config do
  on roles(:app) do
    within release_path do
      execute :bundle, 'config build.pg --with-pg-config=/usr/pgsql-9.4/bin/pg_config --local'
    end
  end
end

I have the necessary packages installed:

postgresql94-server.x86_64
postgresql94-devel.x86_64
postgresql94-libs.x86_64
libpqxx.x86_64
libpqxx-devel.x86_64

Here are the capistrano* gems I have installed

bundle list | grep capistrano
* capistrano (3.3.5)
* capistrano-bundler (1.1.4)
* capistrano-rails (1.1.2)
* capistrano-rbenv (2.0.3)
* capistrano-stats (1.1.1)

What am I missing here to successfully install pg with bundler? Please leave a comment if you need any additional information and I will update this post.

like image 904
Wes Avatar asked Mar 02 '15 16:03

Wes


2 Answers

The postgres binaries are not in the path. Symlink them in to a directory in your path and you should be good: ln -s /usr/pgsql-9.4/bin/p* /usr/local/bin.

Did you build postgres or install it from yum?

like image 191
JoePasq Avatar answered Nov 05 '22 17:11

JoePasq


Just posting the solution for PostgreSQL 11. If someone lands here.

sudo yum install epel-release

sudo yum install postgresql11-llvmjit

sudo yum install postgresql11-devel postgresql11-libs

Then run

gem install pg -v '1.2.3' -- --with-pg-config=/usr/pgsql-11/bin/pg_config 

Thats it

like image 1
Mir Adnan Avatar answered Nov 05 '22 19:11

Mir Adnan