How To Resolve VirtualBox Guest Additions: Kernel Headers Not Found For Target Kernel Error

In this example, I install a CentOS in a VirtualBox virtual machine. Then I click the virtual machine to focus it, and then I click Devices —> Insert Guest Additions CD image… menu item in the virtual machine top menu bar to install additions image like below picture. But during the installation process, I meet an error with the error message VirtualBox Guest Additions: Kernel headers not found for target kernel 3.10.0-1062.el7.x86_64. This article will tell you how to fix it.

1. Reproduce VirtualBox Guest Additions: Kernel Headers Not Found For Target Kernel Error Steps.

  1. Click Devices —> Insert Guest Additions CD image… menu item.
    virtualbox-install-guest-addtions-cd-image
  2. Then it will popup a dialog in the guest CentOS window like below, click Run button.
    insert-guest-additional-cd-image-popup-dialog
  3. Then it will open a terminal and run the command like the below picture, but you may encounter an error message like the below message also.
    VirtualBox Guest Additions: Kernel headers not found for target kernel
    3.10.0-1062.el7.x86_64. Please install them and execute
    
      /sbin/rcvboxadd setup
    
    modprobe vboxguest failed
    
    The log file /var/log/vboxadd-setup.log may contain further information.
    
    Press Return to close this window..

    virtualbox-guest-additions-kernel-headers-not-found-for-target-kernel

2. Fix VirtualBox Guest Additions: Kernel Headers Not Found For Target Kernel Error Steps.

  1. Open a terminal and run command uname -r to list current linux kernel version.
    $ uname -r
    3.10.0-1062.el7.x86_64
    
  2. Run command ls /usr/src/kernels/ to list all the installed kernels.
  3. If there are no kernels listed or the listed kernel version do not match your CentOS linux kernel version. Then you should run command yum install “kernel-devel-uname-r == $(uname -r)” to install your CentOS linux kernel. This command need root user to run, so first you need to run command su to login use root user.
    $su
    Password:
    
    # yum install "kernel-devel-uname-r == $(uname -r)"
  4. When above install command execute success, you can run ls /usr/src/kernels/ to verify the CentOS kernel has been installed.
    # ls /usr/src/kernels/
    
    3.10.0-1062.el7.x86_64
    
  5. Close the terminal, and you can find the VirtualBox Guest Additions CD has been mounted on the desktop. Right click the CD image and click Open in Terminal menu item in the popup menu list. Then run command ./autorun.sh, then it will open a new tab to install the VirtualBox Guest Additions software.
    $ ./autorun.sh
  6. During above installation process, you may encounter below error message This system is currently not set up to build kernel modules. Please install the gcc make perl packages from your distribution.
    this-system-is-currently-not-set-up-to-build-kernel-modules.-please-install-the-gcc-make-perl-packages-from-your-distribution
  7. Now run command yum install -y gcc perl kernel-headers kernel-devel in a terminal with root user permission to install gcc make perl packages, this command may take some time longer.
    # yum install -y gcc perl kernel-headers kernel-devel
  8. After executing the above command, reboot the CentOS system.
  9. Now go to step 5, and the error will disappear when you install VirtualBox Guest Additions software.
4 4 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

11 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
no-mind

Thank you! Solved the issue of not being able to install the additions.

Sruthi
Sruthi

Thanks for this article. It helped a lot

gary
gary

This article is so helpful, it save me a lot of time. In my case, I install CentOS version 6 on Virtualbox, and it does not install the CentOS kernel development package on the virtual machine, so I need to run the command yum install kernel-devel to install it manually.

But the command install a wrong kernel development package version, then I need to run the command yum list kernel* to get all versions.

To fix this issue, I had to run the command yum update kernel kernel-headers to update the CentOS virtual machine kernel version and then reboot it now with the command reboot now.

But the above steps still can not install the Guest Additions autorun.sh completely, the reason is just like what this article said, the gcc package is not installed correctly. So I run the command yum install gcc to install the Guest Additions successfully. After that, I reboot the CentOS again, now it is ok. I wish my experience can help someone who has same error.

Annie
Annie
Reply to  gary

Thank you so much ! This helped me

Rakesh Singh
Rakesh Singh

Thanks it helped me fixing the issue.

shakil
shakil

Thanks for the detailed info, it was really helpful

Pedro Lopez
Pedro Lopez

Thank you very much! Just starting with Linux and this was very helpful.

K E
K E

Thanks for the how-to reminder. Such a pain in the a$s to forget that ‘this is the way’ and God forbid VirtualBox should have their Guest Additions CD autorun file deal with this!

Kishore Uppala
Kishore Uppala

Thank you, it worked…

Git Hub
Git Hub

That shows error. So, I tried this:

yum install kernel-devel-`uname -r`

which worked fine

SAGAR MARAM
SAGAR MARAM

Thanks for this article. This helped me resolving issue i am facing.

11
0
Would love your thoughts, please comment.x
()
x