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/.

Prerequisites

Check BPF-based Sensor Requirements

Procedure

  1. 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/…

  2. 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/…

  3. To install any necessary available kernel headers, run the following command:
    $ sudo apt install linux-headers-$(uname -r)
  4. 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.
    1. Get the kernel update tool.
      $ sudo wget https://raw.githubusercontent.com/pimlie/ubuntu-mainline-kernel.sh/master/ubuntu-mainline-kernel.sh  
    2. To list the available kernel versions, run the following command:
      $ sudo ubuntu-mainline-kernel.sh -r
    3. To install a newer supported kernel version, run the following command:
      $ sudo ubuntu-mainline-kernel.sh -i <version>
    4. To install kernel header packages for the new kernel version, run the following command:
      $ sudo apt install linux-headers-<version>
    5. To reboot into the new kernel, run the following command:
      $ sudo reboot