Ruby pg gem "Can't find the PostgreSQL client library (libpq)"
The pg gem compiles a native extension that links against the PostgreSQL client library, libpq. The build fails because libpq (and its headers) or pg_config is not installed on the runner.
What this error means
Installing the pg gem fails during the native build with "Can't find the PostgreSQL client library (libpq)" or a missing pg_config. The gem cannot link without the Postgres client development files.
checking for pg_config... no
checking for libpq-fe.h... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***Common causes
libpq development files not installed
The pg gem needs libpq-fe.h and the libpq library to compile. The runtime Postgres package alone does not include the -dev headers.
pg_config not on PATH
When pg_config is missing or not on PATH, extconf cannot locate the Postgres installation to link against.
How to fix it
Install the libpq development package
# Debian/Ubuntu
apt-get update && apt-get install -y libpq-dev
# Alpine
apk add --no-cache postgresql-dev
# RHEL/Fedora
dnf install -y postgresql-develPoint the gem at pg_config explicitly
If Postgres is installed in a non-standard prefix, tell the gem where pg_config lives.
gem install pg -- --with-pg-config=/usr/pgsql-16/bin/pg_configHow to prevent it
- Bake libpq-dev into runner images that build the pg gem.
- Use a precompiled pg platform gem where one is published.
- Keep the Postgres client dev package version aligned across CI and prod.