How to Install Specific Linux Kernel Headers

Abstract: Resolve compilation failures for external kernel modules by installing the exact Linux kernel headers matching the running system version.

Created: 2026-10-16 by

To install specific Linux kernel headers, you must match the exact version string of your currently running kernel. Use uname -r to identify this version, then install the corresponding package via your distribution's package manager (such as apt on Debian-based systems or dnf on RHEL-based systems). This process ensures that external modules, like proprietary drivers or DKMS-built software, compile correctly against the active kernel source.

Identifying Your Current Kernel Version

The most critical step in installing kernel headers is ensuring the version matches your running system exactly. If you install headers for a different version, compilation will fail because the internal structures and macros will not align with the loaded kernel module. To find your precise version string, open a terminal and execute the following command:
uname -r
This command returns output similar to 5.15.0-46-generic or 6.1.0-9-amd64. You need every part of this string, including the architecture suffix if present. For example, on Ubuntu systems, the generic flavor often includes -generic, while server kernels might use -server. On Debian, you might see -amd64. Copy this entire string, as it will be used to construct the package name or search query for your installer. It is important to note that simply knowing the major version number (like 5.15 or 6.1) is insufficient. Package managers require the full revision string to locate the correct binary. If you have recently updated your kernel but are still logged into an old session, uname -r might show the older version until you reboot. Always verify the version after a reboot if you suspect a mismatch.

Installing Headers on Debian-Based Systems

For users of Ubuntu, Debian, Linux Mint, and Kali Linux, the Advanced Package Tool (apt) is the standard method for managing kernel components. The package naming convention usually follows the pattern linux-headers-version. First, update your local package index to ensure you can access the latest available versions:
sudo apt update
Next, install the headers using the version string identified earlier. Replace <version> with your actual output from uname -r:
sudo apt install linux-headers-<version>
If you are unsure of the exact package name, you can search for it using apt-cache search. For instance:
apt-cache search linux-headers | grep <version>
This helps confirm the package exists before attempting installation. In some cases, particularly on Kali Linux, users may encounter errors related to dpkg if the package database is corrupted. If you see "E: Sub-process /usr/bin/dpkg returned an error code," you should first run sudo dpkg --configure -a to fix broken configurations before retrying the header installation. Refer to our guide on fixing dpkg errors if you face persistent package management issues. After installation, verify that the files exist by checking the directory /lib/modules/<version>/build. This symbolic link points to the extracted source tree required for building out-of-tree modules.

Installing Headers on RHEL-Based Systems

Red Hat Enterprise Linux, Fedora, CentOS, and Rocky Linux use the DNF or YUM package managers. Note that modern distributions have largely transitioned from yum to dnf, though yum often remains a symlink for backward compatibility. It is best practice to use dnf directly to avoid deprecation warnings. The package naming convention here typically involves kernel-devel and sometimes kernel-headers. The kernel-devel package contains the full development environment needed to compile modules, while kernel-headers provides only the C header files for user-space programs. For most driver installations, you need kernel-devel. Install the matching development packages with:
sudo dnf install kernel-devel-<version> kernel-headers-<version>
If you do not know the exact version, you can list available kernel packages:
dnf list available kernel-devel* | grep <version>
Ensure that the kernel-devel version matches the kernel version exactly. Mismatches here are a common cause of build failures for VirtualBox guest additions or NVIDIA drivers. If you previously attempted an installation that failed due to dependency conflicts, cleaning the cache with sudo dnf clean all and retrying may resolve the issue.

Verifying the Installation

Regardless of the distribution, verification is essential before proceeding with driver compilation. Navigate to the modules directory for your specific kernel version:
cd /lib/modules/$(uname -r)/build
If the directory exists and contains files such as Makefile and Kbuild, the installation was successful. If you receive a "No such file or directory" error, the headers were not installed correctly, or the version string used during installation did not match the running kernel. Double-check your uname -r output and repeat the installation steps. Properly installed headers allow tools like DKMS (Dynamic Kernel Module Support) to automatically rebuild modules when the kernel is updated. This is crucial for maintaining functionality of third-party drivers across system updates. For more information on managing kernel tasks and isolated cores, you may find our article on Ubuntu kernel task isolation helpful.

Frequently Asked Questions

Do I need to reboot after installing kernel headers?

No, a reboot is not required immediately after installation. However, you must be running the kernel version whose headers you just installed. If you installed headers for a new kernel version but are still booted into the old one, the build process will fail because the paths will not match.

What is the difference between kernel-headers and kernel-devel?

kernel-headers contains only the C header files necessary for compiling user-space applications that interact with the kernel. kernel-devel includes the headers plus the Makefiles and configuration scripts required to compile out-of-tree kernel modules, such as graphics drivers or network adapters. You generally need kernel-devel.

Why does my DKMS build fail even with headers installed?

This usually indicates a version mismatch between the running kernel and the installed headers. Verify that uname -r matches the version string of the installed linux-headers or kernel-devel package exactly. Even a minor patch difference (e.g., 5.15.0-46 vs 5.15.0-47) will cause compilation to fail.

Can I install headers for multiple kernel versions simultaneously?

Yes, you can install headers for any number of kernel versions. This is useful if you dual-boot or keep fallback kernels. However, only the headers for the currently running kernel (as shown by uname -r) will be actively used by DKMS or manual builds unless you specify otherwise.

How do I remove kernel headers?

You can remove them using your package manager. For Debian/Ubuntu, use sudo apt purge linux-headers-<version>. For RHEL/Fedora, use sudo dnf remove kernel-devel-<version>. Removing unused headers frees up disk space but does not affect the running system.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More