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

How is Livepatch safeguarded against bad actors?

Canonical Livepatch is a security patching automation tool which supports reboot-less security updates for the…

3 hours ago

Accelerating data science with Apache Spark and GPUs

Apache Spark has always been very well known for distributing computation among multiple nodes using…

3 hours ago

Cut data center energy costs with bare metal automation

Data centers are popping up everywhere. With the rapid growth of AI, cloud services, streaming…

1 day ago

Build the future of *craft: announcing Starcraft Bounties!

Our commitment to building a thriving open source community is stronger than ever. We believe…

1 day ago

NodeJS 18 LTS EOL extended from April 2025 to May 2032 on Ubuntu

The clock was ticking: Node.js 18’s upstream End of Life (EOL) The OpenJS Foundation is…

1 day ago

Native integration now available for Pure Storage and Canonical LXD

June 25th, 2025 – Canonical, the company behind Ubuntu, and Pure Storage, the IT pioneer…

2 days ago