10

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.

Wes
  • 537
  • 4
  • 25

4 Answers4

20

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?

fearmint
  • 5,276
  • 2
  • 33
  • 45
  • Can your custom task run through Capistrano successfully and independently? What output do you have from Capistrano? – fearmint Mar 10 '15 at 21:56
  • Thanks for the response: here is a gist with the output from capistrano (with debug) https://gist.github.com/whargrove/03ff94d1b6e7648030ed – Wes Mar 11 '15 at 02:24
  • :prepare_bundle_config can't run independently because it uses release_path, so it is only available during the deploy task. – Wes Mar 11 '15 at 02:26
  • BTW, symlinking the postgres binaries to the remote user's path seems to have resolved the issue. Thanks! I will reward the bounty as soon as SO will let me. – Wes Mar 11 '15 at 03:24
  • worked for me as well, I'm running postgresql 9.3 on CentOS 7, thanks a lot – Onur Kucukkece Sep 23 '15 at 16:00
  • @JoePasq you just recovered me out of a 2-day long hair-pulling adventure with one line. Kudos to you sir. – PSCampbell Nov 07 '15 at 00:16
1

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

Mir Adnan
  • 844
  • 11
  • 24
1

Alternatively, if you're using a Mac

brew link postgresql

Or in my case

brew link postgresql@12
Dri
  • 492
  • 4
  • 13
0

I find that if I compile pgsql with source code, and PATH ENV not configed with pgsql/bin, this happends. You can have a try with this.

Bruce
  • 1