How to Install Linux Kernel Headers on Fedora Linux

When you install Linux kernel headers on Fedora, you gain the ability to 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, AMD), building virtualization kernel modules (VirtualBox, VMware), installing DKMS-managed 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 modules), kernel-devel is essential and must match your kernel. The kernel-headers package supports the build process, but its version mismatch does not affect module builds.

Install Linux Kernel Headers and Development Packages

Kernel module compilation requires both kernel-headers and 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 that support the build process.

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 (the latest available version works for all kernels):

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 that compilation requires.

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-managed drivers automatically trigger rebuilds 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)

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)

DKMS Modules Fail to Build After Kernel Update

If DKMS-managed drivers (NVIDIA, VirtualBox) fail to rebuild after a kernel update, ensure kernel-devel matches your new kernel:

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

Then manually trigger DKMS rebuild using akmods (Fedora automatic kernel module system):

sudo akmods --force

Rebuild the initial ramdisk to include the new modules:

sudo dracut --force

Reboot after rebuilding to load the rebuilt kernel modules.

Conclusion

You now have the packages to install Linux kernel headers and compile NVIDIA drivers, VirtualBox kernel modules, Docker components, 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