unable to install pg gem
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/
Related videos on Youtube
Comments
-
Rohit about 2 years
I tried using
gem install pg
but it doesn't seem to work.gem install pg
gives this errorTemporarily 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 over 11 yearsIf you're on a mac, follow this tutorial: matthew.mceachen.us/blog/…
-
0112 almost 7 years@NatchiQ broken link?
-
Raj over 4 yearsin my case the error log said
libpq
was not found, so i installedsudo apt install postgresql postgresql-contrib libpq-dev pgadmin3 -y
-
Jared Menard over 2 yearsTry 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 almost 13 yearsWorked for me by
apt-get install libpq-dev
. Thanks for the hint. -
mraaroncruz over 12 yearsand for me installing postgresql-server-dev-8.4 on ubuntu LTS 10
-
Mark Berry over 12 yearsConfirmation, from the pg gem Wiki homepage: "On Ubuntu, /usr/bin/pg_config is provided by the libpq-dev package."
-
dfrankow about 12 yearspostgresql-devel doesn't exist for debian squeeze. We used postgresql-server-dev-8.4 and that worked.
-
Steve almost 12 yearsThis helped me on a mac, anyone know what the default path is and how to change it?
-
TuK over 11 yearsThis helped me (on Centos 6.2)
-
Hiasinho over 11 yearsWorked for me in openSUSE
zypper in postgresql-devel
. Fixed both the config & the libpq. -
Iain over 11 yearsHad the same issue on Fedora 17 this answer solved it (I used yum install postgres-devel).
-
Pedro over 10 yearsWorked 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 about 10 yearsWorks on OS X Maveric
-
gMale almost 10 yearsFixed the problem for me but on a mac (with homebrew) I had to run this command:
brew install postgresql
-
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 about 9 years
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
on yosemite with Postgres App -
Dan Sandland about 9 yearsfor specific version:
gem install pg -v '0.17.1' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
-
Hoang Le almost 9 yearsThe answer for Mac is true. It's just because we haven't installed PostgreSQL on the machine.
-
Mahattam almost 9 years@Fivell try
brew install postgresql
on mac -
Benoit over 8 yearsThanks, it also works using brew installed postgreSQL # PostgreSQL bin path export PATH=$PATH:/usr/local/Cellar/postgresql/9.5.0/bin/
-
Janusz Lenar about 8 yearsWorked. But on Mac, preceding with
env ARCHFLAGS="-arch x86_64"
was a game changer for me. -
HarlemSquirrel over 7 yearsWorked 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/Versions/9.6/bin/pg_config
-
Lane Rettig almost 7 yearsYes! This was all I needed! Install on clean OS X, no Postgres.app
-
Arthur over 6 yearsOn 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 over 6 yearsI used
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
for OSX 10.12 -
Stephen Silber almost 6 yearsThere 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/Versions/latest/bin/pg_config
-
racar over 4 yearsThis help me on OS X with no brew support (using postgres installer)
-
luigi7up about 3 yearsThanks! I switched from brew installed postgres to Postgress.app and had this problem
-
Greg over 2 yearsmacOS Monterey M1. Added to .zshrc
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/14/bin/
andgem install pg
worked and could then `bundle install in Rails