How to Install Linux Kernel Headers on Fedora

When you install Linux kernel headers on Fedora, you get the userspace headers for building applications, and pairing them with kernel-devel lets you compile kernel modules against your running system. Building kernel modules on Fedora requires the kernel-devel package, which provides the build infrastructure to compile drivers against your running kernel. Whether you need to install NVIDIA graphics drivers, build VirtualBox kernel modules, or develop custom kernel extensions, you must install and match kernel-devel to your kernel version. The kernel-headers package serves a different purpose: it provides C header files for compiling userspace applications against kernel APIs.

Common scenarios requiring these packages include compiling proprietary graphics drivers (NVIDIA), building virtualization kernel modules (VirtualBox, VMware), installing DKMS (Dynamic Kernel Module Support) or akmods-based drivers, and developing custom kernel modules. If you only run standard desktop applications, you can skip these packages. By the end of this guide, you will understand the difference between kernel-headers and kernel-devel, have the correct packages installed for your use case, and know how to verify everything works for module compilation.

Refresh Fedora Packages Before Installation

Before installing kernel development packages, update your Fedora system to ensure all packages are current. An up-to-date system reduces compatibility issues and ensures the kernel-devel version matches your running kernel.

sudo dnf upgrade --refresh

The --refresh option bypasses the DNF cache, ensuring you access the latest package versions directly from repositories. If DNF installs a newer kernel during this update, reboot before continuing so your running kernel matches the available kernel-devel packages.

Check the Current Linux Kernel

Identify your running kernel version before installing development packages. The kernel-devel package must match your active kernel exactly, or module compilation will fail.

Check your running kernel version:

uname -r

You will see output similar to:

6.17.4-100.fc41.x86_64

The kernel version number consists of the major version (6.17), patch level (4), Fedora build number (100), and Fedora release (fc41). You need this exact version when installing kernel-devel to ensure compiled modules load correctly.

Version numbers shown in this guide (6.17.4-100.fc41) are examples. Your system will display your currently installed kernel version. Always install kernel-devel matching your actual kernel version that uname -r shows.

Understanding kernel-headers vs kernel-devel

Fedora separates kernel development files into two packages with different purposes and versioning behavior:

kernel-devel

  • Provides build infrastructure for compiling kernel modules
  • Installs to /usr/src/kernels/
  • Must match your running kernel version exactly
  • Install with kernel-devel-$(uname -r)

kernel-headers

  • Provides C header files for compiling userspace programs that interact with kernel APIs
  • Installs to /usr/include/linux/
  • Updates independently from the kernel (since Fedora 26)
  • Version may not match your running kernel; this is normal

For kernel module compilation (NVIDIA drivers, VirtualBox, DKMS or akmods modules), kernel-devel is essential and must match your kernel. The kernel-headers package is for userspace development and can differ from your running kernel without affecting module builds.

Install Linux Kernel Headers and Development Packages

Kernel module compilation requires kernel-devel. The kernel-devel package provides the Makefiles, scripts, and configuration in /usr/src/kernels/ needed to compile modules. The kernel-headers package provides userspace header files for building applications that interact with kernel APIs, so only install it when you need those headers.

Install kernel-devel matching your exact kernel version:

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

This command uses $(uname -r) to dynamically substitute your running kernel version, ensuring the installed package matches your kernel. The kernel-devel package is essential for module compilation.

Install kernel-headers only if you need userspace headers (for example, building glibc or other system libraries):

sudo dnf install kernel-headers

Unlike kernel-devel, kernel-headers does not require version matching. DNF installs the current version from the repository, which provides the userspace headers needed by glibc and other low-level libraries.

Kernel module compilation also requires build tools. Install the GNU Compiler Collection (gcc for C compilation), make (build automation), and elfutils-libelf-devel (kernel module symbol handling):

sudo dnf install gcc make elfutils-libelf-devel

Systems running DKMS or akmods packages typically rebuild modules after kernel updates, so installing build tools ensures drivers rebuild successfully. For broader development needs beyond kernel modules, consider installing CMake or Rust depending on your project requirements.

Verify Kernel Development Environment

Verify that kernel-devel installed correctly by checking if the kernel build directory exists and contains the files you require:

ls -la /usr/src/kernels/$(uname -r)

You should see build infrastructure files similar to:

total 6128
drwxr-xr-x.  25 root root    4096 Nov 15 10:30 .
drwxr-xr-x.   3 root root    4096 Nov 15 10:30 ..
-rw-r--r--.   1 root root     595 Nov 12 08:00 .config
drwxr-xr-x.   3 root root    4096 Nov 15 10:30 arch
drwxr-xr-x.   3 root root    4096 Nov 15 10:30 block
-rw-r--r--.   1 root root  264372 Nov 12 08:00 Makefile
-rw-r--r--.   1 root root 5765123 Nov 12 08:00 Module.symvers
drwxr-xr-x. 120 root root    4096 Nov 15 10:30 include
drwxr-xr-x.   2 root root    4096 Nov 15 10:30 scripts

If this directory does not exist or appears empty, the kernel-devel package is missing or mismatched.

Verify Package Installation

Confirm that you have kernel-devel installed and it matches your running kernel version:

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

You should see output confirming the package installation:

kernel-devel-6.17.4-100.fc41.x86_64

Check that you have kernel-headers installed (version may differ from your kernel):

rpm -q kernel-headers
kernel-headers-6.17.4-100.fc41.x86_64

The kernel-devel version must match your running kernel exactly. The kernel-headers version may differ since it updates independently when the userspace ABI changes. Fedora considers this version difference normal and it does not affect module compilation.

Troubleshooting Common Issues

Compilation Fails With Missing Header Files

If kernel module compilation fails with errors about missing header files:

fatal error: linux/module.h: No such file or directory
 #include <linux/module.h>
          ^~~~~~~~~~~~~~~~

Check whether you have kernel-devel installed for your running kernel:

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

If the package is not installed, you will see:

package kernel-devel-6.17.4-100.fc41.x86_64 is not installed

Install the matching kernel-devel package:

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

Verify the package is installed and matches your running kernel:

rpm -q kernel-devel-$(uname -r)
kernel-devel-6.17.4-100.fc41.x86_64

Version Mismatch Between Kernel and kernel-devel

If you recently updated your kernel but have not rebooted, kernel-devel may not be available for your running kernel. Check your running kernel version:

uname -r

Compare against installed kernels:

rpm -qa kernel | sort

Example output showing multiple kernel versions:

kernel-6.16.8-200.fc41.x86_64
kernel-6.17.4-100.fc41.x86_64

If you have a newer kernel installed but run an older version, reboot to load the newer kernel. After rebooting, install kernel-devel for the new kernel:

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

Confirm the installed kernel-devel version matches your running kernel:

rpm -q kernel-devel-$(uname -r)
kernel-devel-6.17.4-100.fc41.x86_64

DKMS Modules Fail to Build After Kernel Update

If DKMS (Dynamic Kernel Module Support) or akmods-based drivers (NVIDIA, VirtualBox) fail to rebuild after a kernel update, ensure kernel-devel matches your new kernel:

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

Rebuild modules using the tool that matches your driver packaging. For DKMS packages, run:

sudo dkms autoinstall

For akmods packages, run:

sudo akmods --force

If the driver still fails to load, rebuild the initramfs to include the new modules:

sudo dracut --force

Verify kernel-devel still matches your running kernel, then reboot to load the rebuilt modules:

rpm -q kernel-devel-$(uname -r)
kernel-devel-6.17.4-100.fc41.x86_64

Remove Kernel Development Packages

If you no longer need to build kernel modules, remove the development packages:

sudo dnf remove kernel-devel kernel-headers

If you installed build tools only for module compilation, remove them as well:

sudo dnf remove gcc make elfutils-libelf-devel

Verify the packages are removed:

rpm -q kernel-devel kernel-headers
package kernel-devel is not installed
package kernel-headers is not installed

Conclusion

You now have the packages to install Linux kernel headers and compile NVIDIA drivers, VirtualBox kernel modules, and custom kernel modules. After kernel updates, install kernel-devel for the new version with sudo dnf install kernel-devel-$(uname -r). Verify your setup by confirming /usr/src/kernels/$(uname -r) contains build files.

Leave a Comment

Let us know you are human: