How to Fix the “pg_config executable not found” Error?

The “pg_config” is the command-line tool that enables the user to view and retrieve information about the configuration of the PostgreSQL clusters currently used. The main purpose of the “pg_config” is to search for the libraries and the header files as well as for the interface to PostgreSQL. During the installation of any PostgreSQL cluster such as “psycopg2” (PostgreSQL Database Adapter for Python Programming) the user can encounter the error “pg_config executable not found”.

This post will demonstrate the reasons and solutions for the error “pg_config executable not found”.

  • Reason: Missing “libpq-dev” Library
  • Solution: Install “libpq-dev” Library

Reason: Missing “libpq-dev” Library

The reason for the error “pg_config executable not found” is the missing library of “libpq-dev”. This library contains the header files and libraries for PostgreSQL. This error can be seen in the following image in which the “psycopg2” python module is being installed:

$ pip install psycopg2

Solution: Install “libpq-dev” Library

The error can be fixed by installing the “libpq-dev” library. Here are the commands for various Linux distributions to install the missing library “libpq-dev”:

$ sudo apt install libpq-dev          #For Debian/Ubuntu
$ sudo dnf install libpq5-devel       #For Fedora
$ yum install postgresql-devel        #For CentOS/RHEL
$ sudo pacman -S postgresql-libs      #For Arch
$ brew install postgresql             #for MAC

The “libpq-dev” is installed.

Now, let’s install the “psycopg2” database to check if the error is resolved:

$ pip install psycopg2

The psycopg2 database is installed and the error is resolved.

Conclusion

The reason for the error “pg_config executable not found” is the missing library “libpq-dev” is not installed that contains the header files and library information. To fix this error, install the missing library “libpq-dev”. 

This write-up has illustrated the reason and the solution for the error “pg_config executable not found”.