Installing the PostgreSQL gem with 'gem pq' fails with ERROR: Failed to build gem native extension
21,370
If you are using Ubuntu try to install following lib file
sudo apt-get install libpq-dev
and then gem install pg
worked for me.
Author by
Tushar Khatiwada
I’m an experienced and ambitious web and mobile developer experienced in front end development technologies including Reactjs & React Native.
Updated on July 09, 2022Comments
-
Tushar Khatiwada almost 2 years
I am learning Ruby on Rails and trying to develop an application. In my application I am trying to use the default SQLite database in the Development Mode and PostgreSQL in the Production Mode. But I'm getting the following error while trying to install pg gem using:
gem install pg
Building native extensions. This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension. /home/tusharkhatiwada/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb checking for pg_config... yes Using config values from /usr/bin/pg_config You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application. You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application. 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=/home/tusharkhatiwada/.rvm/rubies/ruby-2.0.0-p247/bin/ruby --with-pg --without-pg --with-pg-config --without-pg-config --with-pg_config --without-pg_config --with-pg-dir --without-pg-dir --with-pg-include --without-pg-include=${pg-dir}/include --with-pg-lib --without-pg-lib=${pg-dir}/ Gem files will remain installed in /home/tusharkhatiwada/.rvm/gems/[email protected]/g ems/pg-0.17.0 for inspection. Results logged to /home/tusharkhatiwada/.rvm/gems/[email protected]/gems/pg-0.17.0/ext /gem_make.out
After that I again tried with
gem install pg -- --with-pg-config= '/usr/bin/pg_config'
and the following error is displayed:Building native extensions with: '--with-pg-config= /usr/bin/pg_config' This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension. /home/tusharkhatiwada/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb --with-pg-config= /us r/bin/pg_config Using config values from sh: 1: : Permission denied sh: 1: : Permission denied 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=/home/tusharkhatiwada/.rvm/rubies/ruby-2.0.0-p247/bin/ruby --with-pg --without-pg --with-pg-config --with-pg-dir --without-pg-dir --with-pg-include --without-pg-include=${pg-dir}/include --with-pg-lib --without-pg-lib=${pg-dir}/ Gem files will remain installed in /home/tusharkhatiwada/.rvm/gems/[email protected]/g ems/pg-0.17.0 for inspection. Results logged to /home/tusharkhatiwada/.rvm/gems/[email protected]/gems/pg-0.17.0/ext /gem_make.out
-
Tushar Khatiwada over 10 yearsI tried it but it also shows errors:
You might want to run 'apt-get -f install' to correct these: The following packages have unmet dependencies: libpq-dev : Depends: libkrb5-dev but it is not going to be installed Depends: comerr-dev but it is not going to be installed libssl-dev : Depends: libssl1.0.0 (= 1.0.1c-4ubuntu8.1) but 1.0.1c-4ubuntu8 is to be installed Recommends: libssl-doc but it is not going to be installed E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
-
santosh over 10 yearssudo apt-get update sudo apt-get install build-essential ruby-dev libpcap-dev
-
Tushar Khatiwada over 10 yearsThis solution didn't work on my VM which was installed in cloud server at Koding but it did solve in my Laptop using Ubuntu.
-
Matt Slagle over 10 yearsThis worked while upgrading gitlab from 5.1 to 6.0 using the turnkey linux version.
-
Paritosh Piplewar over 10 yearswhenever i install postgresql i know that error will occur and i will copy-paste this command to fix this problem by google-ing.
-
Craig Treptow over 10 years@TusharKhatiwada - This fixed it for me in the Koding dev environment: databasically.com/2010/03/05/…
-
Jim over 10 yearsHow did you realise this is what was missing?
-
François about 8 yearsinstalling libpq-dev didnt work for me... but installing the libgmp-dev package did it.
-
Ckt22 over 2 yearsE: Unable to correct problems, you have held broken packages.