How can I find out my kernel source path?

Hi, I am currently trying to instell VirtualBox on my Fedora 34.
I am using the following guide:

Now, in step 2, it says the following:

VirtualBox installation required kernel source code to install required modules, So we need to configure environment variable KERN_DIR to which VirtualBox get kernel source code. In my case latest kernel source is available in 4.16.5-300.fc28.x86_64 directory under /usr/src/kernels/ . Make sure you are using correct source path.

export KERN_DIR=/usr/src/kernels/ uname -r

echo $KERN_DIR /usr/src/kernels/4.16.5-300.fc28.x86_64

I know what my kernel thing (I’m sorry if I’m insulting your IT passion with my noobness) is called by using uname -r (correct me if I’m wrong).
Therefore, I insert my result with the 4.16.5-300.fc28.x86_64 from the guide.
But I don’t know what the path is. The one that is /usr/src/kernels/ in the guide.

How can I find that out?


You are using an OLD version of the kernel. The kernel for current fedora 34 is 5.13.16.

  1. What version of fedora are you running? Fc28 as indicated by your uname output?
  2. What version of VirtualBox are you installing?

Fedora 28 has not been supported for 2 years and a lot has changed in that time.

It is likely with that ancient kernel you may not be able to compile it since those old libraries and code do not fit the requirements for a current version of VirtualBox.

Looking at the VB download site there are several different versions available and it is likely that you need the oldest one there to even have a chance of getting it working.

1 Like

Hi, as you can see, it is not my information but the guide’s.
I’m on


And I want to install the latest VirtualBox version, 6.1.26.

It should be /usr/src/kernels/5.13.16-200.fc34.x86_64/ but you have to have the source installed for this to be true.

dnf install kernel-devel-$(uname -r)

Install the source and then try installing VirtualBox again. Don’t worry about the “export $KERN_DIR” stuff.


Thank you, this worked! :slight_smile:
I am now having a problem with my VM. Maybe you have some advice for me in my new question:

Thank you!

No idea on this one. When I install a VM I set the networking to bridged. Not sure why. It is just the way I’ve always done it. It works, so I never give it a second thought. I will say that I have no VM’s on any strictly wireless hosts. All hosts are hard wired.