How to Fix ‘fatal error: openssl/ssl.h: No such file or directory’ in Linux

Compiling software from source code, building Python packages via pip, compiling Ruby gems, or building C/C++ projects using make in Linux only to be stopped by the compiler diagnostic: ‘fatal error: openssl/ssl.h: No such file or directory – #include <openssl/ssl.h> compilation terminated’ halts the build pipeline. This error indicates that the GCC or Clang preprocessor cannot locate OpenSSL’s C header development files. While virtually every modern Linux distribution ships with the OpenSSL runtime library installed for HTTPS communications, development headers are packaged separately.

Why Does the Compiler Fail to Find openssl/ssl.h?

Linux package management separates compiled shared object runtime libraries (e.g., libssl.so) from the developer header files (.h) required to compile new applications against them:

  • Missing Development Header Packages: The system has the openssl runtime package installed, but lacks the corresponding libssl-dev (Debian/Ubuntu) or openssl-devel (RHEL/Fedora) development package.
  • Non-Standard Header Search Paths: OpenSSL was installed manually from source or via Homebrew/Conda into custom directories (such as /usr/local/ssl or /opt/openssl) that are not in the compiler’s default include path.
  • Cross-Compilation Architecture Mismatch: Compiling a 32-bit binary on a 64-bit multi-arch operating system without multi-arch development headers.
  • Missing pkg-config Configuration: Build scripts failing to execute pkg-config --cflags openssl to query compiler flags dynamically.

Step 1: Install OpenSSL Development Headers on Debian / Ubuntu

On Debian, Ubuntu, Linux Mint, and derivative distributions, OpenSSL header files are provided by the libssl-dev package.

  1. Open your terminal and update your package repository index:
    sudo apt update
  2. Install the OpenSSL development library and base compilation tools:
    sudo apt install -y libssl-dev build-essential pkg-config
  3. Verify that the header file is now present in the standard system include directory:
    ls -l /usr/include/openssl/ssl.h
  4. Re-run your compilation or build command.

Step 2: Install OpenSSL Development Headers on RHEL / CentOS / Fedora / AlmaLinux

Red Hat enterprise derivatives use RPM packaging, where development headers are named with the -devel suffix.

  1. On Fedora, RHEL 8/9, AlmaLinux, or Rocky Linux, execute:
    sudo dnf install -y openssl-devel gcc make pkgconfig
  2. On legacy CentOS 7 systems, use:
    sudo yum install -y openssl-devel gcc make pkgconfig
  3. Verify installation:
    rpm -ql openssl-devel | grep "ssl.h"
  4. The command should output /usr/include/openssl/ssl.h.

Step 3: Install OpenSSL Headers on Arch Linux and Alpine Linux

Different distributions package development headers under distinct naming conventions.

  1. On Arch Linux and Manjaro, header files are bundled directly with the core package:
    sudo pacman -Syu openssl base-devel
  2. On Alpine Linux (frequently used in lightweight Docker containers):
    apk update && apk add --no-cache openssl-dev build-base

Step 4: Specify Include Flags for Custom OpenSSL Installations

If you compiled OpenSSL from source or installed it via Homebrew or Conda into a custom prefix, pass the include and library paths to the compiler.

  1. Locate your custom OpenSSL installation path:
    find / -name "ssl.h" 2>/dev/null
  2. Export the CFLAGS, CPPFLAGS, and LDFLAGS environment variables before compiling:
    export CFLAGS="-I/usr/local/ssl/include"
    export CPPFLAGS="-I/usr/local/ssl/include"
    export LDFLAGS="-L/usr/local/ssl/lib"
  3. For Python pip source builds:
    CPPFLAGS="-I/usr/local/ssl/include" LDFLAGS="-L/usr/local/ssl/lib" pip install package_name

Step 5: Verify pkg-config Resolution

Many build frameworks (such as CMake, Meson, or Autotools) rely on pkg-config to discover header locations.

  1. Test whether pkg-config can locate OpenSSL:
    pkg-config --cflags --libs openssl
  2. The command should output:
    -I/usr/include -lssl -lcrypto
  3. If pkg-config cannot find OpenSSL, specify the PKG_CONFIG_PATH environment variable:
    export PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"

Installing distribution development headers and configuring compiler include paths resolves missing header errors, allowing software builds to compile successfully.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.