17

An error occurred while installing pg (1.0.0), and Bundler cannot continue

I have an issue with the bundle install and cannot complete the installation.

What can I do to finish the bundle?

  find_executable: checking for pg_config... -------------------- no

    --------------------

    find_header: checking for libpq-fe.h... -------------------- no

    "clang -o conftest -I/Users/leotyndall/.rbenv/versions/2.4.2/include/ruby-2.4.0/x86_64-darwin17 -I/Users/leotyndall/.rbenv/versions/2.4.2/include/ruby-2.4.0/ruby/backward -I/Users/leotyndall/.rbenv/versions/2.4.2/include/ruby-2.4.0 -I. -I/Users/leotyndall/.rbenv/versions/2.4.2/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -O3 -Wno-error=shorten-64-to-32  -pipe conftest.c  -L. -L/Users/leotyndall/.rbenv/versions/2.4.2/lib -L. -L/Users/leotyndall/.rbenv/versions/2.4.2/lib  -fstack-protector -L/usr/local/lib     -lruby-static -framework CoreFoundation  -lpthread -ldl -lobjc "
    checked program was:
    /* begin */
    1: #include "ruby.h"
    2: 
    3: int main(int argc, char **argv)
    4: {
    5:   return 0;
    6: }
    /* end */

        "clang -E -I/Users/leotyndall/.rbenv/versions/2.4.2/include/ruby-2.4.0/x86_64-darwin17 - 
             I/Users/leotyndall/.rbenv/versions/2.4.2/include/ruby- 
         2.4.0/ruby/backward - 
         I/Users/leotyndall/.rbenv/versions/2.4.2/include/ruby-2.4.0 -I. - 
         I/Users/leotyndall/.rbenv/versions/2.4.2/include  -D_XOPEN_SOURCE - 
         D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -O3 -Wno- 
         error=shorten-64-to-32  -pipe  conftest.c -o conftest.i"
         conftest.c:3:10: fatal error: 'libpq-fe.h' file not found
         #include <libpq-fe.h>
             ^~~~~~~~~~~~
         1 error generated.
         checked program was:
         /* begin */
         1: #include "ruby.h"
         2: 
         3: #include <libpq-fe.h>
        /* end */

    --------------------


     extconf failed, exit code 1


        An error occurred while installing pg (1.0.0), and Bundler cannot continue.
        Make sure that `gem install pg -v '1.0.0'` succeeds before bundling.
Andy
  • 35,844
  • 6
  • 43
  • 50
Leo Tyndall
  • 171
  • 1
  • 5
  • Try to user lower version of pg, say pg -v '0.18' in your Gemfile – Gaurav Gupta May 10 '18 at 11:45
  • It's probably something with your `$PATH` setup. Can you past the output of `echo "${PATH//:/\n}"` in your terminal? Also your Gemfile ? – lacostenycoder May 10 '18 at 11:45
  • Moved most specific error message to title. Reformatted for clarity. Moved questions to top of text and rephrased for clarity. – Andy May 11 '18 at 03:13
  • I had a similar problem where pg_config could not be found and [This solved my problem](https://stackoverflow.com/a/24217329/1752417) – BlackCoffee Aug 02 '20 at 21:03

4 Answers4

17

For macos, the above answers did not work or were not practical for me. I didn't want to install all of postgres.

$ brew install libpq
$ bundle config --local build.pg --with-opt-dir="/usr/local/opt/libpq"
$ bundle install

Reference: https://michaelrigart.be/install-pg-ruby-gem-without-postgresql/

Michael
  • 3,568
  • 3
  • 37
  • 50
16

Try installing libpq-dev or its equivalent for your OS:

  • For Ubuntu systems: sudo apt-get install libpq-dev
  • On Red Hat Linux (RHEL) systems: yum install postgresql-devel
  • For Mac Homebrew: brew install postgresql
  • For Mac MacPorts PostgreSQL: gem install pg -- --with-pg-config=/opt/local/lib/postgresql[version number]/bin/pg_config
  • For OpenSuse: zypper in postgresql-devel
NARKOZ
  • 27,203
  • 7
  • 68
  • 90
  • On OSX (HeighSierra) I don't find how to install only postgres client. So you have to install postgresql (or simply postgres with brew) to obtain the needed file libpq-fe.h. – JL M May 09 '19 at 21:06
5

I solved this by installing the library

brew install libpqxx

Next, install pg normally... you can use gem

gem install pg

Nabende
  • 61
  • 1
  • 5
3
brew install libpq

gem install pg -v '1.2.3' --source 'https://rubygems.org/' -- --with-pg-config=/opt/homebrew/Cellar/libpq/13.2/bin/pg_config
Fernando Correia
  • 21,803
  • 13
  • 83
  • 116
  • My local path was little different: `/usr/local/opt/libpq/bin/pg_config`, but otherwise this worked a charm. On Big Sur. – marc_alain Nov 05 '21 at 21:48