Can't find the PostgreSQL client library (libpq)

When i try it start my ruby server i get a error that looks like

rails server Could not find pg-0.12.2 in any of the sources Run `bundle install` to install missing gems.

I dont know what to do Thanks for all the help

What happens when you do what the command says:

$ bundle install

Do you have a Gemfile ? You might show it here.

HTH,

Peter

When i do bundle install i get

$ bundle install Fetching source index for http://rubygems.org/ Enter your password to install the bundled RubyGems to your system: Using rake (0.9.2.2) Using multi_json (1.0.4) Using activesupport (3.1.3) Using builder (3.0.0) Using i18n (0.6.0) Using activemodel (3.1.3) Using erubis (2.7.0) Using rack (1.3.6) Using rack-cache (1.1) Using rack-mount (0.8.3) Using rack-test (0.6.1) Using hike (1.2.1) Using tilt (1.3.3) Using sprockets (2.0.3) Using actionpack (3.1.3) Using mime-types (1.17.2) Using polyglot (0.3.3) Using treetop (1.4.10) Using mail (2.3.0) Using actionmailer (3.1.3) Using arel (2.2.1) Using tzinfo (0.3.31) Using activerecord (3.1.3) Using activeresource (3.1.3) Using bundler (1.0.22) Using rack-ssl (1.3.2) Using json (1.6.5) Using rdoc (3.12) Using thor (0.14.6) Using railties (3.1.3) Using rails (3.1.3) Using acts-as-taggable-on (2.2.1) Using acts_as_commentable (3.0.1) Using acts_as_list (0.1.4) Using addressable (2.2.6) Using chosen-rails (0.9.5) from git://github.com/fatfreecrm/chosen-rails.git (at master) Using ajax-chosen-rails (0.1.5) Using annotate (2.4.1.beta1) Using authlogic (3.1.0) Using awesome_print (1.0.2) Using nokogiri (1.5.0) Using ffi (1.0.11) Using childprocess (0.3.1) Using rubyzip (0.9.6.1) Using selenium-webdriver (2.19.0) Using xpath (0.1.4) Using capybara (1.1.2) Using chronic (0.6.7) Using cocaine (0.2.1) Using coffee-script-source (1.2.0) Using execjs (1.2.13) Using coffee-script (2.2.0) Using coffee-rails (3.1.1) Using columnize (0.3.6) Using daemons (1.1.5) Using database_cleaner (0.7.1) Using diff-lcs (1.1.3) Using eventmachine (0.12.10) Using em-websocket (0.3.6) Using factory_girl (2.5.0) Using factory_girl_rails (1.6.0) Using ffaker (1.12.1) Using rspec-core (2.8.0) Using rspec-expectations (2.8.0) Using rspec-mocks (2.8.0) Using rspec (2.8.0) Using rspec-instafail (0.1.9) Using ruby-progressbar (0.0.10) Using fuubar (0.0.6) Using guard (0.10.0) Using guard-livereload (0.4.0) Using guard-rails (0.0.3) Using guard-rspec (0.6.0) Using sass (3.1.12) Using guard-sass (0.5.4) Using spork (0.8.5) Using guard-spork (0.5.1) Using haml (3.1.4) Using headless (0.2.2) Using jquery-rails (1.0.19) Using kgio (2.7.0) Using libv8 (3.3.10.4) Using rbx-require-relative (0.0.5) Using linecache (0.46) Using paperclip (2.5.2) Installing pg (0.12.2) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb checking for pg_config... yes Using config values from /usr/local/bin/pg_config checking for libpq-fe.h... yes checking for libpq/libpq-fs.h... yes checking for PQconnectdb() in -lpq... no checking for PQconnectdb() in -llibpq... no checking for PQconnectdb() in -lms/libpq... no Can't find the PostgreSQL client library (libpq) *** 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=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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   --with-pqlib   --without-pqlib   --with-libpqlib   --without-libpqlib   --with-ms/libpqlib   --without-ms/libpqlib

Gem files will remain installed in /Users/moiseszaragoza/.bundler/tmp/37599/gems/pg-0.12.2 for inspection. Results logged to /Users/moiseszaragoza/.bundler/tmp/37599/gems/pg-0.12.2/ext/gem_make.out An error occured while installing pg (0.12.2), and Bundler cannot continue. Make sure that `gem install pg -v '0.12.2'` succeeds before bundling.

=================== MY GEM LIST

Seems that you are on a Mac

If you installed Postgres on your system using the binaries downloaded directly from postgresql.org website, the following should fix this issue...

PATH=$PATH:/Library/PostgreSQL/9.0/bin sudo gem install pg

Craig

you can type pg_config at the prompt to see environment variable setting if it's in your path, otherwise do a find to locate the binary:

sudo updatedb locate pg_config

you can use grep to narrow down the search

locate pg_config | grep bin

on my linux box, I use something like the following to install gem pg

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

you may need to install the header files if you if you installed postgresql using your system package. I personally just build postgresql from source, which is something you may want to look into if you feel comfortable with this

Point of clarification: there are no Mac binaries available directly from postgresql.org. The are 3 links there which all lead to external sites with installers maintained external to the postgres project, which are built with who knows what options, and installed into unusual locations.

Also, ./configure, make, make install work perfectly well on OS X.

If you installed Postgres on your system using the binaries downloaded directly from postgresql.org website, the following should fix this issue...

Point of clarification: there are no Mac binaries available directly from postgresql.org. The are 3 links there which all lead to external sites with installers maintained external to the postgres project, which are built with who knows what options, and installed into unusual locations.

Also, ./configure, make, make install work perfectly well on OS X.

1 Like

If you are getting this error in Mac M1 pro, Silicon chip

checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)

Install libpq via homebrew and add it to the PATH

brew install libpq
echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
OR ~/bash_profile instead of ~/.zshrc if you use that.

Then do

bundle install # OR
gem install pg

It works for me.

thanks it’s work for me :bouquet: :bouquet:

  1. Install libpq binary as suggested.
$ brew install libpq
  1. Then check if the pg_config exist
$ ls /opt/homebrew/opt/libpq/bin/pg_config
  1. Install the pg gem if pg_config exist
$ gem install pg -- --with-pg-config=/opt/homebrew/opt/libpq/bin/pg_config