Linux kernel development on Rocky Linux depends on two related packages, and the right choice depends on what you are building. Install Linux kernel headers on Rocky Linux with DNF when userspace code needs files under /usr/include/linux/; add kernel-devel when DKMS, NVIDIA drivers, VirtualBox Guest Additions, or another external module needs a build tree for the active kernel.
Rocky Linux 10, 9, and 8 use the same DNF command pattern. Rocky Linux 10 and 9 provide these packages from AppStream, while Rocky Linux 8 provides them from BaseOS. EPEL is not required for
kernel-headersorkernel-devel.
Install Linux Kernel Headers on Rocky Linux
Start by choosing the package role that matches your task. The package names differ from Debian and Ubuntu, so commands such as apt install linux-headers-$(uname -r) or package names such as linux-headers-amd64 do not apply on Rocky Linux.
| Package | Installs | Use When |
|---|---|---|
kernel-headers | Userspace kernel interface headers under /usr/include/linux/ | Compiling userspace programs that include Linux kernel API headers. |
kernel-devel | Kernel build tree under /usr/src/kernels/<kernel-release>/ | Building external kernel modules, DKMS modules, proprietary drivers, and similar module-based software. |
Rocky Linux still provides a yum compatibility alias, but DNF is the normal package-manager command on current Rocky releases. Use DNF for new installs and troubleshooting.
Refresh Rocky Linux Before Installing Headers
Refresh package metadata and apply available updates before installing kernel development packages. These commands use sudo because DNF changes system packages; review the transaction before confirming it, especially on servers where a kernel update needs a planned reboot.
sudo dnf upgrade --refresh
If DNF installs a new kernel, reboot before installing the matching kernel-devel package. The module build tree must match the kernel shown by uname -r after the reboot.
sudo reboot
Check the Active Kernel Release
Check the active kernel release after any reboot. Use this value when installing or verifying kernel-devel.
uname -r
Rocky Linux 10 uses a 6.12.0-...el10_1.x86_64 style string, Rocky Linux 9 uses 5.14.0-...el9_7.x86_64, and Rocky Linux 8 uses 4.18.0-...el8_10.x86_64. The exact build changes with updates, so use your own output for matching package checks.
Install kernel-headers for Userspace Development
Install kernel-headers when your build only needs userspace Linux kernel API headers. This is enough for many C programs that include headers from /usr/include/linux/.
sudo dnf install kernel-headers
Unlike kernel-devel for external module builds, kernel-headers normally follows the current repository package and does not need to match uname -r exactly.
Install kernel-devel for DKMS and Driver Builds
Install kernel-devel when an external module, DKMS workflow, proprietary driver, or guest-tools installer needs the active kernel build tree. This is the package most driver installers mean when they ask for kernel sources on a RHEL-family system.
sudo dnf install kernel-headers "kernel-devel-$(uname -r)"
The quoted package spec asks DNF for the kernel-devel build tree that matches your active kernel. Keep this package installed before following module-based workflows such as installing NVIDIA drivers on Rocky Linux.
Verify Kernel Header Packages on Rocky Linux
Use RPM package checks instead of file counts. Commands such as ls /usr/include | wc -l can show that files exist, but they do not prove which package owns the headers or whether the active kernel build tree is present.
rpm -q kernel-headers
rpm -q "kernel-devel-$(uname -r)"
If you installed only kernel-headers, the second command can report that the matching kernel-devel package is not installed. That is normal unless you need DKMS or another module build workflow.
Confirm that the userspace header path belongs to the kernel-headers package:
rpm -qf /usr/include/linux/version.h
For module builds, confirm that the active kernel has a matching build tree:
test -d "/usr/src/kernels/$(uname -r)" && echo "Matching kernel-devel tree found"
Matching kernel-devel tree found
Update or Remove Kernel Headers on Rocky Linux
Update Kernel Headers and Development Packages
DNF updates installed kernel development packages during normal system upgrades. Use a normal refresh and upgrade so kernel packages, header packages, and dependent system libraries stay in the same repository state:
sudo dnf upgrade --refresh
After a kernel update and reboot, install the exact kernel-devel package for the active kernel if a driver or DKMS workflow needs it:
sudo dnf install kernel-headers "kernel-devel-$(uname -r)"
Remove Kernel Headers and Development Packages
Remove these packages only when you no longer build kernel modules or userspace software that needs Linux kernel headers. Removing them does not remove the running kernel, but DKMS modules and driver installers can fail after future kernel updates until you reinstall the matching packages.
sudo dnf remove kernel-headers kernel-devel
Verify that no kernel-headers or kernel-devel packages remain installed:
rpm -qa | grep -E '^kernel-(headers|devel)-' || echo "Kernel development packages are not installed"
Kernel development packages are not installed
Troubleshoot Linux Kernel Headers on Rocky Linux
DNF Cannot Find kernel-devel for the Running Kernel
A No match for argument error usually means the running kernel and enabled repositories do not currently expose the same package build. Check your active kernel and the available package versions:
uname -r
dnf list --showduplicates kernel-devel kernel-headers
If the active kernel release is missing from the list, update Rocky Linux, reboot into the newest Rocky kernel, and repeat the install command. Do not force a stock Rocky kernel-devel package onto a custom, mainline, or third-party kernel.
Driver Installer Says Kernel Source Tree Is Missing
Many driver installers use “kernel source” language even when they only need the packaged build tree. Verify kernel-devel and the matching directory first:
rpm -q "kernel-devel-$(uname -r)"
test -d "/usr/src/kernels/$(uname -r)" && echo "Matching kernel-devel tree found"
If either check fails, install the matching development package again:
sudo dnf install kernel-headers "kernel-devel-$(uname -r)"
DKMS Package Is Not Available
A No match for argument: dkms error is separate from missing kernel headers. Rocky Linux provides kernel-headers and kernel-devel in its own repositories, but dkms comes from EPEL. Enable EPEL on Rocky Linux before installing DKMS, then keep the matching kernel-devel package installed for module rebuilds.
Debian linux-headers Package Names Do Not Apply
If you copied a Debian or Ubuntu command such as sudo apt install linux-headers-$(uname -r), translate the package role rather than the exact package name. Rocky Linux uses kernel-headers for userspace headers and kernel-devel-$(uname -r) for the active kernel build tree.
Mainline or Custom Kernel Headers Are Missing
Third-party kernels need headers or development packages from the same source as the kernel itself. If you use a mainline kernel on Rocky Linux, follow that kernel source’s matching header or development package workflow instead of installing Rocky’s stock kernel-devel package.
Conclusion
Rocky Linux can now support userspace header builds with kernel-headers and module builds with the matching kernel-devel tree. Keep the development package aligned after kernel updates, and use RPM ownership checks or the /usr/src/kernels/$(uname -r) path instead of file counts when troubleshooting build errors.


Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed in published comments:
<code>command</code>command<strong>bold</strong><em>italic</em><blockquote>quote</blockquote>