Linux kernel headers provide the C header files that define the interface between the kernel and userspace programs. You need these headers when compiling software that interacts with kernel APIs, building custom kernel modules, or installing drivers like NVIDIA graphics drivers and VirtualBox Guest Additions. By the end of this guide, you will have kernel headers installed on Rocky Linux and understand when you also need the kernel-devel package for module compilation.
This guide covers Rocky Linux 8, 9, and 10. Commands work identically across these versions unless noted otherwise.
Understand the Difference: kernel-headers vs kernel-devel
Before installing, you should understand the difference between these two related packages, as your use case determines which one you need.
kernel-headers
- Provides C header files in
/usr/include/linux/ - Required for compiling userspace programs that call kernel APIs
- Does not need to match your running kernel version exactly
- Smaller download (approximately 3 MB)
kernel-devel
- Provides build infrastructure in
/usr/src/kernels/ - Required for compiling kernel modules (drivers, DKMS modules)
- Must match your running kernel version for module compilation
- Larger download (approximately 23 MB) with many dependencies
If you plan to install NVIDIA drivers on Rocky Linux, VirtualBox Guest Additions, or any DKMS-based driver, you need both packages. DKMS (Dynamic Kernel Module Support) automatically recompiles kernel modules when you upgrade to a new kernel, which is why matching versions are critical. For userspace development work, kernel-headers alone is sufficient.
Update Rocky Linux Before Installation
Before installing kernel headers, update your system to ensure you have the latest kernel and package metadata. This step matters because kernel-related packages should align with your installed kernel version.
sudo dnf upgrade --refresh
If DNF installs a new kernel package during this update, reboot your system before proceeding. Installing kernel headers for a kernel version you have not yet booted into can cause version mismatches.
sudo reboot
Check Your Current Kernel Version
Next, verify which kernel version your system is currently running. This information helps you confirm that the installed headers match your kernel.
uname -r
The command outputs your active kernel version. On Rocky Linux 10, this looks like:
6.12.0-124.21.1.el10_1.x86_64
This version string breaks down as follows: 6.12.0 is the upstream kernel version, 124.21.1 is the Rocky Linux build number, el10_1 indicates Rocky Linux 10.1, and x86_64 is the architecture. On Rocky Linux 9, you would see a version like 5.14.0-611.16.1.el9_7.x86_64, and on Rocky Linux 8, something like 4.18.0-553.89.1.el8_10.x86_64.
Install Linux Kernel Headers
Rocky Linux provides kernel headers through the AppStream repository, which is enabled by default. The simplest approach installs the latest available version:
sudo dnf install kernel-headers
This command installs the kernel headers corresponding to the latest kernel available in your repositories. For most users, this approach works well because the headers typically match the most recent kernel package.
Install Headers for Your Running Kernel
If your running kernel differs from the latest available version, or if you need an exact match, specify the version explicitly:
sudo dnf install kernel-headers-$(uname -r)
The $(uname -r) substitution inserts your running kernel version into the package name, ensuring an exact match. Use this method when you encounter version mismatch errors during driver compilation.
Install kernel-devel for Module Compilation
For kernel module compilation, install kernel-devel alongside kernel-headers. This package provides the Makefiles, scripts, and source files needed to build modules.
sudo dnf install kernel-headers kernel-devel
The kernel-devel package pulls in several dependencies including GCC, make, and Perl. On a minimal installation, expect approximately 80-90 packages to install. Once complete, the kernel build tree appears at /usr/src/kernels/<version>/.
Verify the Installation
Once installation completes, confirm that the packages are present using RPM. This verification step ensures both packages installed correctly:
rpm -qa | grep -E '^kernel-headers|^kernel-devel'
The output lists the installed packages with their version numbers:
kernel-headers-6.12.0-124.21.1.el10_1.x86_64 kernel-devel-6.12.0-124.21.1.el10_1.x86_64
Alternatively, verify the header files exist in their expected location:
ls /usr/include/linux/ | head -5
a.out.h acct.h acrn.h adb.h adfs_fs.h
If you installed kernel-devel, also verify the kernel source tree:
ls -d /usr/src/kernels/*
/usr/src/kernels/6.12.0-124.21.1.el10_1.x86_64
This directory contains the kernel Makefile, configuration, and module build infrastructure that DKMS and driver installers require.
Troubleshooting Common Issues
If you encounter problems during or after installation, these solutions address the most common causes.
Package Not Found for Your Kernel Version
If you receive an error like “No match for argument: kernel-headers-X.X.X”, the headers for your exact kernel version may not be available. This typically happens when your kernel is newer than your repository metadata or when running a non-standard kernel.
First, check which kernel-headers versions are available:
dnf list kernel-headers --showduplicates
Installed Packages kernel-headers.x86_64 6.12.0-124.21.1.el10_1 @appstream Available Packages kernel-headers.x86_64 6.12.0-124.8.1.el10_1 appstream kernel-headers.x86_64 6.12.0-124.13.1.el10_1 appstream kernel-headers.x86_64 6.12.0-124.16.1.el10_1 appstream kernel-headers.x86_64 6.12.0-124.20.1.el10_1 appstream kernel-headers.x86_64 6.12.0-124.21.1.el10_1 appstream
If your running kernel is not in the list, update your system and reboot into a supported kernel version. For users running the mainline kernel on Rocky Linux, headers must be obtained from the same source as the kernel itself.
DKMS or Driver Build Fails
When DKMS or a driver installer reports missing kernel sources, the issue is usually a missing kernel-devel package or a version mismatch. Verify that both packages are installed and match your running kernel:
rpm -qa | grep -E 'kernel-headers|kernel-devel' && uname -r
The package versions should match the uname -r output. If they differ, install the matching versions:
sudo dnf install kernel-headers-$(uname -r) kernel-devel-$(uname -r)
Update Kernel Headers
Kernel headers update automatically when you run a standard system upgrade with dnf upgrade. However, if you need to update them specifically without upgrading other packages, use this command:
sudo dnf upgrade kernel-headers kernel-devel
When you install a new kernel package and reboot, DNF can install matching headers for that kernel version. After rebooting into the new kernel, run the install command again to ensure the headers match:
sudo dnf install kernel-headers-$(uname -r) kernel-devel-$(uname -r)
To keep your system responsive and reduce upgrade times, consider following our guide to increase DNF speed on Rocky Linux.
Remove Kernel Headers
If you no longer need the kernel development packages, remove them with DNF:
sudo dnf remove kernel-headers kernel-devel
DNF identifies and removes unused dependencies that were installed alongside these packages. If some dependencies remain because other packages still need them, DNF keeps them automatically. To verify the removal completed successfully, run:
rpm -qa | grep -E '^kernel-headers|^kernel-devel' || echo "Packages removed successfully"
Packages removed successfully
Removing kernel-headers and kernel-devel does not affect your running system. These packages only contain development files, not the actual kernel. However, any DKMS modules will fail to rebuild after kernel updates until you reinstall these packages.
Conclusion
You now have Linux kernel headers installed on Rocky Linux, along with an understanding of when you need kernel-devel for module compilation. These packages enable driver installation, DKMS module building, and userspace development against kernel APIs.