Installing kernel headers on Linux (Ubuntu, Debian, Fedora, Raspberry Pi)

Many drivers and programs build their own kernel module during installation – VirtualBox, the NVIDIA drivers, ZFS or various Wi-Fi drivers, for example. This requires the kernel headers matching the running kernel. If they are missing, the installation aborts with messages such as “Kernel headers not found” or “DKMS: build failed”.

Ubuntu

sudo apt install linux-headers-$(uname -r)

$(uname -r) is automatically replaced by the version of the running kernel. To have the headers come along automatically with future kernel updates, install the metapackage as well:

sudo apt install linux-headers-generic

Debian

sudo apt install linux-headers-$(uname -r)
sudo apt install linux-headers-amd64     # metapackage for future kernels (64-bit PC)

Fedora

On Fedora the files needed for building modules are called kernel-devel:

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

Raspberry Pi OS

Since Raspberry Pi OS “Bookworm” the packages follow the Debian scheme. The easiest way here, too, is:

sudo apt install linux-headers-$(uname -r)

On older releases the package was called raspberrypi-kernel-headers.

Checking that the headers match

uname -r
ls -l /lib/modules/$(uname -r)/build

If the second command shows a valid link to the header directory, everything is fine. dkms status shows the state of all DKMS modules; after installing the headers, a failed module can be rebuilt with sudo dkms autoinstall.

Typical pitfall: missing reboot

If a kernel update has been installed but the machine has not been rebooted yet, the old kernel is still running – uname -r then returns a version whose headers may no longer be in the repositories at all. In that case reboot first and install the headers afterwards.

Over time old kernels and their headers pile up and take up space on /boot. How to remove them safely is covered in the article Ubuntu & Debian: safely removing old kernel versions.

Originally published in 2014, completely revised in November 2026.