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-devPoint 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 installHow 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
gem "Failed to build gem native extension" in CIFix "ERROR: Failed to build gem native extension" in CI - a gem with a C extension could not compile because…
mysql2 gem "cannot find mysqlclient" native build in CIFix mysql2 "Can't find mysql client" native build error in CI - the MySQL/MariaDB client development library…
gem "You have to install development tools first" in CIFix "You have to install development tools first" during a native gem build in CI - the runner has no C compi…