Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To install headers for the kernel currently running, use APT to install the package whose name includes that exact kernel release:

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

First check that APT can see the package with apt-cache policy linux-headers-$(uname -r). Kernel headers must match the kernel you intend to build a module for; a different version or flavour may not be suitable.

Check which kernel needs headers

Run uname -r to print the kernel release currently running. The command substitution in linux-headers-$(uname -r) inserts that release into the package name, including its version and any flavour suffix. Debian’s guidance uses this exact-release approach for installing headers needed to build an out-of-tree module (Debian SystemTap; Debian out-of-tree module building).

uname -r
apt-cache policy linux-headers-$(uname -r)

In the policy output, look for a candidate version. If APT reports no candidate, it cannot currently offer that matching package from the configured repositories.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install headers for the running kernel

  1. Refresh APT’s package metadata: sudo apt update.
  2. Check the exact package: apt-cache policy linux-headers-$(uname -r).
  3. Install it: sudo apt install linux-headers-$(uname -r).

For module builds, the conventional build path is /lib/modules/$(uname -r)/build. Debian describes this path and the matching header package in its out-of-tree module building instructions. Verify that the release you are targeting is the one intended for the module; the running kernel may not be the target if you are preparing a build for another kernel.

Choose between an exact package and an Ubuntu flavour metapackage

Ubuntu documents two useful package routes: install headers for one exact kernel release, or install a metapackage that follows a kernel flavour. The right choice depends on whether you need headers for a particular kernel ABI or want APT to track a supported flavour. Ubuntu’s examples include generic and lowlatency (Ubuntu NVIDIA driver installation).

Route Useful when How to check
Exact running-kernel package: linux-headers-$(uname -r) You need headers for the release shown by uname -r. Run apt-cache policy linux-headers-$(uname -r).
Ubuntu flavour metapackage, such as linux-headers-generic You want to follow a kernel flavour rather than select one exact release. Confirm that the installed headers match the kernel release you intend to build against.

A metapackage follows its flavour; do not assume that installing one makes headers for every installed or custom kernel available. Check the package state on the target system.

If APT cannot find the matching package

A missing candidate does not identify the cause by itself. The kernel may come from a different source or flavour, or the required package may not be available in the repositories enabled on that machine. Identify the distribution release and kernel release, then inspect the configured APT repositories. Ubuntu recommends checking the exact package with apt-cache policy; package availability depends on the system’s release and configuration (Ubuntu NVIDIA driver installation).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Do not install headers for a different ABI or flavour as a guess.
  • If the kernel is custom-built or supplied by another provider, consult that provider for the corresponding headers; the standard distribution package instructions do not specify every vendor’s method.
  • Once the matching package is available, install it and use the build path under /lib/modules/<target-release>/build for the kernel you are targeting.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Headers, DKMS, and Secure Boot are separate concerns

Kernel headers are software files, not a physical accessory. Debian describes them as C header files used in building kernel modules (Debian KernelHeaders). Installing them supplies build inputs; it does not by itself sign a module.

Ubuntu’s NVIDIA instructions distinguish DKMS modules from precompiled modules and state that, in the documented setup, DKMS modules are not signed with Canonical’s key. If Secure Boot is enabled, follow the signing and key-enrollment instructions for the driver and kernel rather than expecting headers to resolve module-signing requirements (Ubuntu NVIDIA driver installation).

Separately, Ubuntu cautions that locally built kernel packages may be unsigned and will not boot with Secure Boot enabled unless signed with an enrolled Machine Owner Key. That warning concerns booting a self-built kernel image, not installing distribution header packages (Ubuntu kernel build documentation).

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.