"apt-get install linux-headers-generic" installed in directory different than $(uname-r)

Viewed 9743

I am a newbie on Linux kernel. I was trying to install Linux header on ubuntu. I first tried

sudo apt-get install linux-headers-$(uname -r)

However, since the output of $(uname -r) is 4.4.0-18362-Microsoft, the installation gives me the error:

E: Unable to locate package linux-headers-4.4.0-18362-Microsoft                                                         
E: Couldn't find any package by glob 'linux-headers-4.4.0-18362-Microsoft'                                              
E: Couldn't find any package by regex 'linux-headers-4.4.0-18362-Microsoft'

By searching on the internet, I found that linux headers do not exist on WSL. Therefore I tried something that is recommended on the internet, by doing

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install linux-generic
sudo apt-get install linux-headers-generic

Then I got a successful installation under /usr/src/linux-headers-4.15.0-51-generic and /usr/src/linux-headers-4.15.0-51. However, my team uses a makefile where the directory of the Linux headers is referred to using $(uname -r), which is still 4.4.0-18362-Microsoft. So whenever I do make, it still gives me the error

can't read /usr/src/linux-headers-4.4.0-18362-Microsoft/...

Is there anyway I can install the headers or change $(uname -r) such that I can use $(uname -r) to refer to the directory?

2 Answers

Create a symlink from /usr/src/linux-headers-4.15.0-51-generic to /usr/src/linux-headers-4.4.0-18362-Microsoft/

sudo ln -s /usr/src/linux-headers-4.15.0-51-generic /usr/src/linux-headers-4.4.0-18362-Microsoft

I'm using Ubuntu 18.04.2 LTS and had a similar issue - but it wasn't Microsoft:

E: Unable to locate package linux-headers-4.15.0-51-generic-generic
E: Couldn't find any package by glob 'linux-headers-4.15.0-51-generic-generic'
E: Couldn't find any package by regex 'linux-headers-4.15.0-51-generic-generic'

For me worked fine after I did as below:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install linux-generic
sudo apt-get install linux-headers-$(uname -r)
Related