i want to write a device driver but not able to find the header file can someone please help me find them?Also if someone can point out some important site links that would be really appreciated
5 Answers
You should be able to install the kernel header files for the currently running kernel by running the following in a terminal:
sudo apt-get install linux-headers-$(uname -r)
In general, the kernel header packages are named linux-header-* where "*" indicates the version & variant (generic, server, etc.).
-
3hey thanks but could you tell me what does generic, server, etc means i want to write (kernel driver)– coderNov 6, 2011 at 3:39
-
14This won't install the headers for future updates automatically and you'll have to re-run this command every time. Therefore, it's recommended to install the metapackage instead, as described in another answer. Jun 25, 2013 at 21:13
-
Note: this doesn't put them in the GCC include path, you still need
-I
. Aug 8, 2015 at 7:34 -
1Note: For this to work, the line appropriate
deb-src
line must be present in/etc/apt/sources.list
.– VoracOct 24, 2016 at 11:38 -
I'm sorry for it doesn't work at which the version of my kernel is 4.19.57-v7+. How come? Jul 2, 2020 at 7:33
You can just type:
sudo apt-get install linux-headers-generic
if you are on a Desktop installation. The apt-get will solve the dependencies and install the correct version of kernel headers.
-
18
-
3Or
linux-headers-virtual
if your running a VM in an Openstack instance... Sep 18, 2013 at 6:41 -
1In Debian Wheezy I get the error message "Package linux-headers-generic is not available, but is referred to by another package. [...] E: Package 'linux-headers-generic' has no installation candidate" Apr 27, 2015 at 3:10
-
4@IQAndreas the
linux-headers-generic
package is ubuntu specific. On Debian you should usesudo apt-get install linux-headers-$(uname -r)
Apr 28, 2015 at 16:00 -
I have linux-headers-generic installed on 18.04 but still don't have the headers for the newest and current kernel version. Maybe it's just a bug with this version, I've compiled kernel modules in earlier versions so I must've had the correct headers back then. Jan 19 at 10:11
Case of Obsolete kernel package
This should cover another problem when: the currently running kernel is obsolete, meaning it's not in the repository anymore neither its headers. So the best thing to do is to update the kernel to last version in the repository.
linux-generic
is a meta package to keep current version of the kernel & its headers:
sudo apt-get update
sudo apt-get install linux-generic
Note: Depending on your Ubuntu edition, See if you need linux-lowlatency
(Ubuntu Studio), linux-signed-generic
or linux-virtual
.
-
2None of the other solutions worked for me when trying to install a driver. Thanks you. Jan 5, 2016 at 3:33
-
2an almost equivalent for debian is called
linux-headers-amd64
(for amd64 systems, obviously) Apr 20, 2017 at 23:24 -
1Amazing,
linux-headers-amd64
did the job for me for my Gitlab pipelines! Thelinux-headers-$(uname -r)
did not work though. Voting up. Mar 8, 2022 at 9:47
Or if you have aptitude installed: sudo aptitude install linux-headers-$(uname -r)
-
5
these commands should work:
sudo apt-get dist-upgrade -y
systemctl reboot
sudo apt-get install linux-headers-$(uname -r)
sudo apt-get upgrade linux-headers-$(uname -r)
for better instruction checkout this video
-
1He is just asking how to install headers, why would you recommend upgrading the distribution? Do not follow these steps if you just want to download the headers.– AFP_555Nov 25, 2020 at 16:58