Skip to content
Latchkey

pg gem "Can't find the 'libpq-fe.h' header" in CI

The pg gem compiles against the PostgreSQL client library and needs its development headers. "Can't find the libpq-fe.h header" means libpq-dev (the client -dev package) is not installed on the runner.

What this error means

Installing pg fails with "checking for libpq-fe.h... no" and "Can't find the 'libpq-fe.h' header", ending the native build.

gem
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.

Common causes

libpq-dev is not installed

The PostgreSQL client development package that provides libpq-fe.h is missing from the runner image.

Only the client binary, not the headers, is present

The runtime libpq is installed but the -dev headers needed to compile are not.

How to fix it

Install the PostgreSQL client dev package

Add libpq-dev (Debian/Ubuntu) before bundling so the header is available.

Terminal
sudo apt-get update
sudo apt-get install -y libpq-dev

Point pg at a custom libpq location

If libpq is installed in a nonstandard prefix, tell the build where to find it.

Terminal
bundle config build.pg --with-pg-config=/usr/pgsql/bin/pg_config
bundle install

How to prevent it

  • Install libpq-dev in a setup step before bundle install.
  • Bake libpq-dev into a custom runner image for Postgres apps.
  • Prefer a precompiled pg platform gem where one is available.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →