Installing pg gem on Ubuntu (extconf.rb failed)

Installing pg gem on Ubuntu (extconf.rb failed)

Last updated:

If, upon trying to run gem install pg command to install the pg gem you get an error message that looks like this:

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
ERROR: Failed to build gem native extension.
/home/felipe/.rvm/rubies/ruby-head/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.

Then you need to run this first

$ sudo apt-get install libpq-dev

Dialogue & Discussion