Categories: TutorialsUbuntu

[Fixed] pkg-config script could not be found in Linux

Are you also facing the “pkg-config script could not be found” or “configure: error: pkg-config is required

Sponsored
error while compiling your favorite program? Then just run one of the following commands based on your Linux distribution, and the problem will be resolved.
# On Debian, Ubuntu, Kali Linux, Linux Mint, Zorin OS, Pop!_OS, etc.
$ sudo apt install pkg-config

# On Red Hat, Fedora, CentOS, Rocky Linux, AlmaLinux, etc.
$ sudo dnf install pkgconfig

# On Arch Linux, Manjaro, BlackArch, Garuda, etc.
$ sudo pacman -S pkgconf

# For macOS
$ brew install pkg-config

Interested in knowing more about this package? Then, let’s start.

What is pkg-config in Linux?

pkg-config is a helper tool that is used to provide the correct path of header files or libraries to the compiler option during the compilation of an application or program. 

It often happens that the path of header files or libraries varies for different systems; instead of hard-coding them, pkg-config helps determine the proper paths to header files and code to link them to your software project.

It’s free, open-source, and originally released for Linux and other UNIX-like systems, but later ported to Windows and macOS. The program code has been rewritten multiple times, with the first implementation by James Henstridge and the current one maintained by Tollef Fog Heen.

Let’s now see how pkg-config can help us find the correct path to pass to the compiler.

Usage of pkg-config command

pkg-config helps during the compilation of applications by providing paths to the installed header files and libraries. To learn its usage, you must first find out the list of available packages on your system using this command:

$ pkg-config --list-all

Output:

Once you have selected the package name, you mainly use the following two options:

  • –cflags“: It will provide the path for the “-I” (include) compiler option, typically for header files.
  • –libs“: It will return the path for the “-L” (libs) compiler option, which is often used to link compiled libraries to new code.

Let’s say you want to find the compiler option for the “python3” package, you can run:

Sponsored
$ pkg-config --libs --cflags python3

Output:

In this scenario, there is only one path for each “include” and “libs” compiler option. However, certain packages, like “gtk+-3.0” may offer multiple paths.

$ pkg-config --libs --cflags gtk+-3.0

Output:

These outputs can be used for program compilation. You can either copy-paste it or assign it to a custom environment variable. For example, exporting the output of the pkg-config command to the compiler via environment variables would look like this:

$ export COMPILER_PATHS=$(pkg-config --libs --cflags LIBRARYNAME)

Afterward, you can use this environment variable to compile your program, like below:

$ COMPILER -c MYPROGRAM ${COMPILER_PATHS}  

If you’re not a programmer and aren’t involved in compilation, you might wonder why this matters. However, if you do end up involved in compiling other programs via source code, the “configure” file you use to set up the environment might include pkg-config for providing paths. In that case, pkg-config must be installed on your system, or you might encounter the error mentioned in the article introduction.

I hope you understood the concept of pkg-config—what it is, when to use it, and why you should care. If you have further questions, feel free to ask them in the comments.

Till then, peace!

The post [Fixed] pkg-config script could not be found in Linux appeared first on Linux TLDR.

Ubuntu Server Admin

Recent Posts

Canonical Releases Ubuntu 25.04 Plucky Puffin

The latest interim release of Ubuntu introduces “devpacks” for popular frameworks like Spring, along with…

2 days ago

Ubuntu 25.04 (Plucky Puffin) Released

Ubuntu 25.04, codenamed “Plucky Puffin”, is here. This release continues Ubuntu’s proud tradition of integrating…

3 days ago

Extended Security Maintenance for Ubuntu 20.04 (Focal Fossa) begins May 29, 2025

Ubuntu released its 20.04 (Focal Fossa) release 5 years ago, on March 23, 2020. As…

3 days ago

Ubuntu 20.04 LTS End Of Life – activate ESM to keep your fleet of devices secure and operational

Focal Fossa will reach the End of Standard Support in May 2025, also known as…

4 days ago

Ubuntu MATE 25.04 Release Notes

Ubuntu MATE 25.04 is ready to soar! 🪽 Celebrating our 10th anniversary as an official…

4 days ago

Ubuntu Weekly Newsletter Issue 887

Welcome to the Ubuntu Weekly Newsletter, Issue 887 for the week of April 6 –…

6 days ago