Guides 11792 Published by

The article explains why having matching kernel headers is essential when compiling drivers or modules and how missing them can derail builds. It walks through checking the running kernel version with `uname -r`, updating DNF, installing Development Tools, and pulling the exact `kernel-devel` and `kernel-headers` packages for both EL8 and EL9, noting the slight naming differences. The guide also covers common pitfalls such as disabled repos, older headers after an update, multiple kernels, or build failures, offering concrete commands to resolve each issue. In short, by keeping headers in sync with the active kernel you can avoid cryptic compiler errors and keep your system tidy, making the process straightforward for both novices and seasoned sysadmins.



Installing Linux Kernel Headers on Rocky Linux 8/9 – A No‑Nonsense Guide

When you’re compiling a driver, building a custom kernel module, or just trying to keep your system tidy, missing the exact kernel headers can turn a simple task into an exercise in frustration. This article shows how to grab the right header files for Rocky Linux 8 (EL8) and Rocky Linux 9 (EL9), explains why each step matters, and gives you a quick way to troubleshoot the usual hiccups.

Why You Need the Right Headers

Kernel headers provide the interface between user‑space build tools and the kernel’s internal APIs. If your headers are out of sync with the kernel you’re actually booting, compilation will fail with cryptic errors like “invalid relocation” or “missing symbol”. The last thing you want is to waste time chasing a mismatch.

Check Which Kernel You're Running
uname -r

The output looks something like 4.18.0-240.el8.x86_64. Keep that string handy—your header package must match it exactly. On a system with multiple kernels installed, the kernel you boot into is the one that matters.

Installing Linux Kernel Headers on EL8

1. Update your package index

   sudo dnf makecache

This guarantees you’re pulling the newest available packages.

2. Install the development tools (optional but handy)

   sudo dnf groupinstall -y "Development Tools"

It pulls gcc, make, and related goodies so you don’t have to hunt them down later.

3. Grab the matching header package

   sudo dnf install -y kernel-devel-$(uname -r) kernel-headers-$(uname -r)

The kernel-devel package contains source files; kernel-headers supplies the exported symbols your compiler needs. Using $(uname -r) ensures you don’t end up with a header from an older or newer kernel.

4. Verify the installation

   rpm -q kernel-devel | grep $(uname -r)

If that prints a line, you’re good to go.

Installing Linux Kernel Headers on EL9

The process is almost identical, but note that Rocky 9 ships with a newer default kernel and slightly different package names:

1. Update the repo data

   sudo dnf clean all && sudo dnf makecache

2. Install dev tools if you haven’t already

   sudo dnf groupinstall -y "Development Tools"

3. Pull the exact headers

   sudo dnf install -y kernel-devel-$(uname -r) kernel-headers-$(uname -r)

The command is the same; just be aware that EL9 kernels are often z‑prefixed (e.g., 5.14.0-1022.el9.x86_64).

4. Double‑check

   rpm -q kernel-devel | grep $(uname -r)

If it shows up, you’re set.

Troubleshooting Common Pitfalls
  • "Package does not exist" error – You might be on a minimal install that lacks the el8 or el9 repository enabled. Run sudo dnf config-manager --set-enabled PowerTools for EL8, or ensure the rocky-9-baseos-rpms repo is active for EL9.
  • Headers older than your kernel – If you previously had an older kernel and forgot to reboot after an update, you could end up with mismatched headers. Reboot into the latest kernel (sudo systemctl reboot) then re‑install.
  • Multiple kernels installed – Use rpm -qa | grep 'kernel.-base' to see all kernel packages. Match the header version to the one listed as Running Kernel* in uname -r.
  • Build failures after installing headers – Some modules require additional kernel source patches or a specific GCC version. Check the module’s README; sometimes yum install gcc-c++ is also needed.

I’ve seen this happen after a bad driver update: the system was still booting the old kernel, but the new headers had already been installed. The build would bomb out with “undefined reference” errors until I synced the two versions. Once they matched, everything compiled cleanly.

That’s all there is to it. Grab the right header files, keep them in sync with your running kernel, and you’ll avoid a lot of headaches down the road. Give it a whirl, and if something still trips you up, drop me a line.