When installing the VirtualBox Guest Additions on CentOS 7 you might get an error saying the sources of the linux kernel could not be found.
Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR= and run Make again. Stop.
This error can be solved by installing the kernel developer package and setting the KERN_DIR environment variable.
$ sudo yum install kernel-devel $ sudo uname -r # store the variable $ echo export KERN_DIR=/usr/src/kernels/[uname output] >> ~/.bashrc
So what we do here is to intall the kernel-developer package and, get the current kernel version and set the environment variable to KERN_DIR. Now restart the virtual machine and install the Guest Additions again. The error should have gone.
Furthermore, developer tools need to be installed via yum groupinstall ‘Developer Tools’. The group name may differ if you are using a different language but english.