To check for kernel headers and install them if necessary on Ubuntu systems, perform the following steps.
When they are properly installed, the required kernel headers are located under
/usr/src/linux-headers-$(uname -r)/include/.
Procedure
- To determine whether kernel headers are installed, run the following command:
$ sudo apt list linux-headers-$(uname -r)
If the package is installed, the output will be similar to the following. An i
or i+
in the left column signifies that the package is installed.
linux-headers-<version>-generic/…
- To determine whether the kernel headers are available to install, run the following command:
$ sudo apt search linux-headers-$(uname -r)
If the package is available, the output will be similar to the following:
linux-headers-<version>-generic/…
- To install any necessary available kernel headers, run the following command:
$ sudo apt install linux-headers-$(uname -r)
- If the kernel headers packages are not installed and are not available, update the kernel to a supported version and install the matching kernel headers.
Note: This action requires a reboot.
- Get the kernel update tool.
$ sudo wget https://raw.githubusercontent.com/pimlie/ubuntu-mainline-kernel.sh/master/ubuntu-mainline-kernel.sh
- To list the available kernel versions, run the following command:
$ sudo ubuntu-mainline-kernel.sh -r
- To install a newer supported kernel version, run the following command:
$ sudo ubuntu-mainline-kernel.sh -i <version>
- To install kernel header packages for the new kernel version, run the following command:
$ sudo apt install linux-headers-<version>
- To reboot into the new kernel, run the following command: