Linux kernel is an open-source computer operating system. All Linux operating systems are based on this kernel, as well as deployed on traditional computer systems like all personal computers and servers. In this article, we will explain ‘How to Install Kernel Headers in Ubuntu’ using the default package manager. Kernel Headers are in C header files for Linux kernel. The kernel headers are meant to collect function codes like kernel modules or device drivers. The kernel headers should match the existing kernel version of the system. In the previous article, you have seen that ‘Linux Tutorial for Beginners All the Basics You Need To Know‘.
Follow the below Steps to Install Kernel Headers in Ubuntu:
First check the kernel version installed in your Ubuntu system and see if the version matches matched with the kernel header package, enter the following command.
itsmarttricks@mangesh:~$ uname -r 4.15.0-33-generic
Also Read- Top Basic Linux Commands for Beginners.
itsmarttricks@mangesh:~$ apt search linux-headers-$(uname -r) Sorting... Done Full Text Search... Done linux-headers-4.15.0-33-generic/bionic-updates,bionic-security,now 4.15.0-33.36 amd64 [installed,automatic] Linux kernel headers for version 4.15.0 on 64 bit x86 SMP
Also Read- How to Install LAMP Stack with PhpMyAdmin in Ubuntu
In the Ubuntu system, the files in the kernel header of ‘/usr/src‘ are found in the directory. Run the following command to see if the already installed kernel version is matching with the kernel headers.
itsmarttricks@mangesh:~$ ls -l /usr/src/linux-headers-$(uname -r) total 1532 drwxr-xr-x 3 root root 4096 Aug 23 23:08 arch lrwxrwxrwx 1 root root 32 Aug 15 18:20 block -> ../linux-headers-4.15.0-33/block lrwxrwxrwx 1 root root 32 Aug 15 18:20 certs -> ../linux-headers-4.15.0-33/certs lrwxrwxrwx 1 root root 33 Aug 15 18:20 crypto -> ../linux-headers-4.15.0-33/crypto lrwxrwxrwx 1 root root 40 Aug 15 18:20 Documentation -> ../linux-headers-4.15.0-33/Documentation lrwxrwxrwx 1 root root 34 Aug 15 18:20 drivers -> ../linux-headers-4.15.0-33/drivers lrwxrwxrwx 1 root root 35 Aug 15 18:20 firmware -> ../linux-headers-4.15.0-33/firmware lrwxrwxrwx 1 root root 29 Aug 15 18:20 fs -> ../linux-headers-4.15.0-33/fs drwxr-xr-x 4 root root 4096 Aug 23 23:08 include lrwxrwxrwx 1 root root 31 Aug 15 18:20 init -> ../linux-headers-4.15.0-33/init lrwxrwxrwx 1 root root 30 Aug 15 18:20 ipc -> ../linux-headers-4.15.0-33/ipc
Before installing kernel headers, run the following command in the terminal and update Ubuntu packages.
itsmarttricks@mangesh:~$ sudo apt update [sudo] password for itsmarttricks: Ign:1 http://dl.google.com/linux/chrome/deb stable InRelease Get:2 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB] Hit:3 http://in.archive.ubuntu.com/ubuntu bionic InRelease Hit:4 http://dl.google.com/linux/chrome/deb stable Release Get:6 http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB] Hit:7 http://in.archive.ubuntu.com/ubuntu bionic-backports InRelease Fetched 172 kB in 4s (43.1 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done 26 packages can be upgraded. Run 'apt list --upgradable' to see them.
Also Read- How To Install Python 3.6 on Linux Using Terminal Interface.
After updating the ubuntu packages index, install the Linux Kernel headers package by executing the following commands.
itsmarttricks@mangesh:~$ sudo apt install linux-headers-$(uname -r) Reading package lists... Done Building dependency tree Reading state information... Done linux-headers-4.15.0-33-generic is already the newest version (4.15.0-33.36). linux-headers-4.15.0-33-generic set to manually installed. The following packages were automatically installed and are no longer required: gconf-service gconf-service-backend gconf2-common libde265-0 libgconf-2-4 libheif1 libjavascriptcoregtk-1.0-0 libmecab2 libwebkitgtk-1.0-0 mecab-ipadic mecab-ipadic-utf8 mecab-utils mypaint-brushes Use 'sudo apt autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 26 not upgraded.
Check the matching kernel headers using the following command which is installed in your system.
itsmarttricks@mangesh:~$ ls -l /usr/src/linux-headers-$(uname -r) total 1532 drwxr-xr-x 3 root root 4096 Aug 23 23:08 arch lrwxrwxrwx 1 root root 32 Aug 15 18:20 block -> ../linux-headers-4.15.0-33/block lrwxrwxrwx 1 root root 34 Aug 15 18:20 Kconfig -> ../linux-headers-4.15.0-33/Kconfig drwxr-xr-x 2 root root 4096 Aug 23 23:08 kernel lrwxrwxrwx 1 root root 30 Aug 15 18:20 lib -> ../linux-headers-4.15.0-33/lib lrwxrwxrwx 1 root root 35 Aug 15 18:20 Makefile -> ../linux-headers-4.15.0-33/Makefile lrwxrwxrwx 1 root root 29 Aug 15 18:20 mm -> ../linux-headers-4.15.0-33/mm drwxr-xr-x 3 root root 4096 Aug 23 23:08 tools lrwxrwxrwx 1 root root 33 Aug 15 18:20 ubuntu -> ../linux-headers-4.15.0-33/ubuntu lrwxrwxrwx 1 root root 30 Aug 15 18:20 usr -> ../linux-headers-4.15.0-33/usr
Also Read- How to Install MySQL 8.0 in Ubuntu
That’s all, In this article, we have explained How to Install Kernel Headers in Ubuntu. I hope you enjoy this article. If you like this article, then just share it. If you have any questions about this article, please comment.