How to Install Linux Kernel Headers on Fedora
When you’re building kernel‑module software or tweaking the kernel itself, those header files are the bread and butter. In this guide we’ll cover every way to get them onto a fresh Fedora install—no fluff, just straight‑to‑the‑point steps.
Why You Need the Header Files
Kernel headers expose the internal APIs that modules need to link against. Without them you’ll see “missing header file” errors when compiling things like VirtualBox extensions or custom drivers. If you’ve ever updated your kernel and found all your third‑party modules suddenly stopped loading, it was probably because the matching headers were missing.
Quick Check: Are Headers Already on Your System?
rpm -q kernel-devel
If you get a package name back, the headers are present for the running kernel. If not—or if it says “package is not installed”—you need to install them.
Installing via dnf (The Easiest Route)
1. Update your package index
sudo dnf update – keeps everything fresh so you get the right header version that matches your current kernel.
2. Install the matching development package
sudo dnf install kernel-devel-$(uname -r)
Why this matters: The kernel-devel package contains headers for the exact kernel release you’re running, preventing version mismatches that cause compilation errors.
3. Verify installation
ls /usr/src/kernels/$(uname -r)/include/linux/
If you see a directory full of .h files, you’re good to go.
Tip: On Fedora spins like Fedora Server you might also need the kernel-headers package. It’s lightweight and sometimes required by certain build tools.
When dnf Fails: Manually Grab the Headers
If dnf can’t find a matching kernel-devel, maybe your kernel is from a custom repo or an edge release.
1. Download the RPM directly
sudo dnf install https://mirrors.fedoraproject.org/pub/fedora/linux/releases/$(rpm -E %fedora)/Everything/x86_64/os/Packages/k/kernel-devel-*.rpm
Replace * with your kernel version. You can find the exact URL by browsing the Fedora mirror.
2. Install it locally
sudo rpm -Uvh /path/to/kernel-devel-*.rpm
3. Confirm – same ls command from earlier.
Building Your Own Kernel Header Package
Occasionally you’re working with a custom kernel build, and the pre‑compiled headers won’t cut it.
1. Pull the source tarball
sudo dnf download --source kernel
2. Extract it
rpmdev-extract kernel-*.src.rpm cd kernel-*/SOURCES/ tar xf vmlinuz-$(uname -r).tar.gz
3. Run the header extraction script
sudo ./scripts/headers.sh
The script copies all relevant headers into /usr/src/kernels/$(uname -r).
4. Make sure your build tools point here – many make scripts automatically look there, but you can export KERNEL_DIR=/usr/src/kernels/$(uname -r) if needed.
Final Verification: Test a Simple Module
Try compiling the tiny “hello world” module from the Linux kernel source:
cd /usr/src/kernels/$(uname -r)/samples/ make hello
If you see modules_loaded.ko without errors, your headers are correctly installed.
That’s all there is to it. Once those header files are in place, you can focus on the fun part—writing modules and tweaking kernel behavior instead of chasing missing symbol errors.