install kernel headers in ubuntu

How to Install Kernel Headers in Ubuntu & Debian

Every Linux system has kernel headers that are basically C files that contain functions & structures required to compile code that interfaces with kernels. These are mostly kernel modules, device drivers and some user programs. It is important to note that you must install kernel headers that match your kernel version. Another thing to remember while installing kernel header is that you need to follow the same approach used that was used to upgrade your kernel. So if you had used a package manager to install kernel, then you need to install kernel using package manager only. On the other hand, if you had compiled the kernel from source, you need to compile the kernel headers from source. In this article, we will learn how to install kernel headers in Ubuntu & Debian systems, using default package manager.


How to Install Kernel Headers in Ubuntu & Debian

Here are the steps to install kernel headers in Ubuntu & Debian.

First step is to check the version of installed kernel as well as header package that matches your kernel. Open terminal and run the following command for this purpose.

$ uname -r
$ apt search linux-headers-$(uname -r)

You will see the following kind of output.

In Ubuntu/Debian systems, kernel files are located in /usr/src. You can check if the kernel headers that match your kernel are already installed on your system with the following command.

$ ls -l /usr/src/linux-headers-$(uname -r)

In the above output, it is evident that matching kernel headers are not installed on your system. But before you install matching kernel headers, you need to update package index, get information about latest packages, with the following command.

$ sudo apt update

Then run the following command to install kernel headers package, depending on your kernel version.

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

Lastly, check if the right kernel header version has been installed on your system, with the following command.

$ ls -l /usr/src/linux-headers-$(uname -r)

In this article, we have learnt how to install kernel headers in Ubuntu & Debian Linux. The important points to remember is to install a kernel header package that matches your kernel version, and also use the same installation method (using package manager or compiling source) that was used to install or upgrade the kernel.

Kernel is the heart of every Linux system and it controls pretty much all the critical processing. Kernel headers are used by modules and drivers to interface with kernel. They are part of kernel although they are distributed separately. That is to make it easier to modify the kernel headers to work with various driver versions, and also isolate kernel from changes and modifications in kernel headers. Most kernels already contain kernel headers and also most Linux systems automatically upgrade kernel headers when they upgrade kernels. So in most cases, you may not need to install kernel headers. In case, it is corrupted or accidentally deleted, then you can use the above steps to install them.

Also read:

How to Migrate from GitHub to BitBucket
How to Transfer All MySQL Databases from One Server to Another
How to List All Virtual Hosts in NGINX
How to Remove Docker Images, Containers and Volumes
How to Rebuild RPM Database in CentOS/RHEL

Leave a Reply

Your email address will not be published. Required fields are marked *