Published on

Ubuntu 20.04 Resolving :: Can't find the 'libpq-fe.h header when trying to install pg gem

Authors

This issue has plagued me for ages where none of the proposed solutions worked.

The main solution suggested for Ubuntu is install libpq-dev: sudo apt-get install libpq-dev

This then results in errors itself when trying to install:

libpq-dev : Depends: libpq5 (= 12.4-0ubuntu0.20.04.1) but 12.4-1.pgdg20.04+1 is to be installed

¯_(ツ)_/¯

After reading more through the answers here I saw the solution proposed for Mac:

brew install postgresql

I did have Linuxbrew installed but generally prefer to use apt as not everything works well in Linuxbrew (compared to Homebrew on Mac). But out of complete frustration, I tried it... and it worked!

I have not tried brew in a while on Linux. It seems to have improved significantly for Linux. I love Brew on Mac, its API is just so clean and most common tools can be installed using it on Mac and it also generally does not need sudo to install most programs. I will be using plenty more of brew on Linux.

The only thing I would suggest is after installing it stop and disable the Postgres DB unless you want it running locally:

sudo systemctl stop postgresql.service
sudo systemctl disable postgresql.service

In my case I just need it for the dev dependencies, I generally prefer using Docker/Compose for local dev DBs as I can spin them up and wipe them very easily without breaking my system.