unable to install pg gem

158,604

Solution 1

Answered here: Can't install pg gem on Windows

There is no Windows native version of latest release of pg (0.10.0) released yesterday, but if you install 0.9.0 it should install binaries without issues.

Solution 2

I had this problem, this worked for me:

Install the postgresql-devel package, this will solve the issue of pg_config missing.

sudo apt-get install libpq-dev

Solution 3

Issue is gem dependency so before installing pg make sure you have installed "libpq-dev"

Ubuntu systems:

sudo apt-get install libpq-dev

RHEL systems:

yum install postgresql-devel

Mac:

brew install postgresql

Solution 4

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

Solution 5

@Winfield said it:

The pg gem requires the postgresql client libraries to bind against. This error usually means it can't find your Postgres libraries. Either you don't have them installed or you may need to pass the --with-pg-dir= to your gem install.

More than that, you only need --with-pg-config= to install it.

On a Mac

If, by any chance, you also installed postgres through the website bundle on mac, it will be on somewhere like /Applications/Postgres.app/Contents/Versions/9.3/bin.

So, either you pass it on the gem install:

gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config

Or you set the PATH properly. Since that might be too much, to temporarily set the PATH:

export PATH=%PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin/
Share:
158,604

Related videos on Youtube

Rohit
Author by

Rohit

https://www.rohithere.com/about/

Updated on March 18, 2022

Comments

  • Rohit
    Rohit about 2 years

    I tried using gem install pg but it doesn't seem to work.

    gem install pg gives this error

    Temporarily enhancing PATH to include DevKit...
    Building native extensions.  This could take a while...
    ERROR:  Error installing pg:
            ERROR: Failed to build gem native extension.
    
    C:/Ruby/bin/ruby.exe 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=C:/Ruby/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 C:/Ruby/lib/ruby/gems/1.8/gems/pg-0.10.1 for
    inspection.
    Results logged to C:/Ruby/lib/ruby/gems/1.8/gems/pg-0.10.1/ext/gem_make.out
    
    • Noah W. Smith
      Noah W. Smith over 11 years
      If you're on a mac, follow this tutorial: matthew.mceachen.us/blog/…
    • 0112
      0112 almost 7 years
      @NatchiQ broken link?
    • Raj
      Raj over 4 years
      in my case the error log said libpq was not found, so i installed sudo apt install postgresql postgresql-contrib libpq-dev pgadmin3 -y
    • Jared Menard
      Jared Menard over 2 years
      Try opening a new terminal tab and trying again. That worked for me. I had just installed psql, and the window I was trying to install the gem in didn't have psql in its path.
  • Ryanmt
    Ryanmt almost 13 years
    Worked for me by apt-get install libpq-dev. Thanks for the hint.
  • mraaroncruz
    mraaroncruz over 12 years
    and for me installing postgresql-server-dev-8.4 on ubuntu LTS 10
  • Mark Berry
    Mark Berry over 12 years
    Confirmation, from the pg gem Wiki homepage: "On Ubuntu, /usr/bin/pg_config is provided by the libpq-dev package."
  • dfrankow
    dfrankow about 12 years
    postgresql-devel doesn't exist for debian squeeze. We used postgresql-server-dev-8.4 and that worked.
  • Steve
    Steve almost 12 years
    This helped me on a mac, anyone know what the default path is and how to change it?
  • TuK
    TuK over 11 years
    This helped me (on Centos 6.2)
  • Hiasinho
    Hiasinho over 11 years
    Worked for me in openSUSE zypper in postgresql-devel. Fixed both the config & the libpq.
  • Iain
    Iain over 11 years
    Had the same issue on Fedora 17 this answer solved it (I used yum install postgres-devel).
  • Pedro
    Pedro over 10 years
    Worked for me on OS X, but with path to /Applications/Postgres.app/Contents/MacOS/bin/pg_config (I have a standalone Postgres.app)
  • Marek Kirejczyk
    Marek Kirejczyk about 10 years
    Works on OS X Maveric
  • gMale
    gMale almost 10 years
    Fixed the problem for me but on a mac (with homebrew) I had to run this command: brew install postgresql
  • Alex LaFroscia
    Alex LaFroscia over 9 years
    @Fivell Late to the game with the answer here, but if you have Homebrew installed, brew install postgresql will get you the packages you need.
  • skilleo
    skilleo about 9 years
    gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Version‌​s/9.4/bin/pg_config on yosemite with Postgres App
  • Dan Sandland
    Dan Sandland about 9 years
    for specific version: gem install pg -v '0.17.1' -- --with-pg-config=/Applications/Postgres.app/Contents/Version‌​s/9.3/bin/pg_config
  • Hoang Le
    Hoang Le almost 9 years
    The answer for Mac is true. It's just because we haven't installed PostgreSQL on the machine.
  • Mahattam
    Mahattam almost 9 years
    @Fivell try brew install postgresql on mac
  • Benoit
    Benoit over 8 years
    Thanks, it also works using brew installed postgreSQL # PostgreSQL bin path export PATH=$PATH:/usr/local/Cellar/postgresql/9.5.0/bin/
  • Janusz Lenar
    Janusz Lenar about 8 years
    Worked. But on Mac, preceding with env ARCHFLAGS="-arch x86_64" was a game changer for me.
  • HarlemSquirrel
    HarlemSquirrel over 7 years
    Worked for me on OS X 10.11 with psql app 9.6 and gem version 0.18.4 gem install pg -v '0.18.4' -- --with-pg-config=/Applications/Postgres.app/Contents/Version‌​s/9.6/bin/pg_config
  • Lane Rettig
    Lane Rettig almost 7 years
    Yes! This was all I needed! Install on clean OS X, no Postgres.app
  • Arthur
    Arthur over 6 years
    On Centos 7 yum install postgresql-devel solved my error related to pg_config for installing the 'pg' .gem. By the way I opted to use the just released PostgreSQL 10
  • Tim Krins
    Tim Krins over 6 years
    I used gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Version‌​s/latest/bin/pg_conf‌​ig for OSX 10.12
  • Stephen Silber
    Stephen Silber almost 6 years
    There is a symlink folder called latest inside of the Postgres.app contents folder that is useful in case 9.3 is no longer shipped. gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Version‌​s/latest/bin/pg_conf‌​ig
  • racar
    racar over 4 years
    This help me on OS X with no brew support (using postgres installer)
  • luigi7up
    luigi7up about 3 years
    Thanks! I switched from brew installed postgres to Postgress.app and had this problem
  • Greg
    Greg over 2 years
    macOS Monterey M1. Added to .zshrc export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/14/b‌​in/ and gem install pg worked and could then `bundle install in Rails