Error

"pkg-config not found" — How to Fix

Install the `pkg-config` package using your system's package manager, as it is required by Cargo to locate native dependencies and their compiler flags.

Install the pkg-config package using your system's package manager, as it is required by Cargo to locate native dependencies and their compiler flags. On Linux, use apt or dnf; on macOS, use Homebrew; and on Windows, install it via Chocolatey or the MSYS2 environment.

On Ubuntu or Debian-based systems, run:

sudo apt-get update
sudo apt-get install pkg-config

On Fedora or RHEL-based systems:

sudo dnf install pkg-config

On macOS with Homebrew:

brew install pkg-config

On Windows, if you are using MSYS2 (common for cross-compilation or specific toolchains), install it via the package manager:

pacman -S mingw-w64-x86_64-pkg-config

If you are using Docker, ensure your base image includes pkg-config. For example, in a Dockerfile:

FROM rust:1.75
RUN apt-get update && apt-get install -y pkg-config

After installation, verify it is available by running pkg-config --version in your terminal. If you still encounter the error, ensure your PATH environment variable includes the directory where pkg-config was installed. This is common when installing via custom paths or within specific shells like zsh or fish.

If you are building a project that depends on a specific library (like openssl or libsqlite3), you might also need to install the development headers for that library, as pkg-config only provides the path and flags; the actual headers must be present on the system. For instance, on Ubuntu, you would run sudo apt-get install libssl-dev alongside pkg-config.

In CI/CD environments like GitHub Actions, you can install it in the workflow YAML:

- name: Install pkg-config
  run: |
    sudo apt-get update
    sudo apt-get install -y pkg-config

Once pkg-config is installed and accessible, re-run your cargo build command. The error should resolve, allowing Cargo to correctly link against the required native libraries.