Ubuntu – The headers for the current running kernel were not found. – Solution

Symptoms

The following message appears during the building stage of VirtualBox Guest Additions:

Building the VirtualBox Guest Additions kernel modules
The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.

Solution

First check whether your system includes kernel headers matching your currently running kernel. For example:

# dpkg --get-selections | grep linux-headers
linux-headers-3.13.0-53                         install
linux-headers-3.13.0-53-generic                 install
linux-headers-generic                           install
# uname -r
3.13.0-53-generic

The above message about missing header can be a little bit misleading so make sure that all other components required to build VirtualBox Guest Additions are available. Run ta below command to ensure that all compilation prerequisites to build VirtualBox Guest Additions are met before you run build command:

# apt-get install linux-headers-`uname -r` dkms build-essential