Ubuntu – Error! Your kernel headers for kernel 3.5.0-25-generic cannot be found

12.10kernel

I run dist-upgrade and I ended up with this error:

Error! Your kernel headers for kernel 3.5.0-25-generic cannot be found.

Please install the linux-headers-3.5.0-25-generic package,

or use the –kernelsourcedir option to tell DKMS where it's located

run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.5.0-25-generic
/boot/vmlinuz-3.5.0-25-generic`

I have these installed dkms xserver-xorg xserver-xorg-core

I have tried these questions

Unable to install VirtualBox on Ubuntu 12.10: Kernel headers cannot be found and

Error: kernel headers not found. (But they are in place) But didn't help much

Here is the output below:

suhaib@suhaib-sda8:~$ sudo apt-get dist-upgrade 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
  linux-image-3.5.0-25-generic linux-image-extra-3.5.0-25-generic
The following packages will be upgraded:
  linux-image-generic
1 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 39.6 MB of archives.
After this operation, 153 MB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://ca.archive.ubuntu.com/ubuntu/ quantal-updates/main linux-image-3.5.0-25-generic amd64 3.5.0-25.39 [11.9 MB]
Get:2 http://ca.archive.ubuntu.com/ubuntu/ quantal-updates/main linux-image-extra-3.5.0-25-generic amd64 3.5.0-25.39 [27.7 MB]
Get:3 http://ca.archive.ubuntu.com/ubuntu/ quantal-updates/main linux-image-generic amd64 3.5.0.25.31 [2,442 B]
Fetched 39.6 MB in 13s (2,894 kB/s)                                            
Selecting previously unselected package linux-image-3.5.0-25-generic.
(Reading database ... 142958 files and directories currently installed.)
Unpacking linux-image-3.5.0-25-generic (from .../linux-image-3.5.0-25-generic_3.5.0-25.39_amd64.deb) ...
Done.
Selecting previously unselected package linux-image-extra-3.5.0-25-generic.
Unpacking linux-image-extra-3.5.0-25-generic (from .../linux-image-extra-3.5.0-25-generic_3.5.0-25.39_amd64.deb) ...
Preparing to replace linux-image-generic 3.5.0.17.19 (using .../linux-image-generic_3.5.0.25.31_amd64.deb) ...
Unpacking replacement linux-image-generic ...
Setting up linux-image-3.5.0-25-generic (3.5.0-25.39) ...
Running depmod.
^[[1;3B^[[1;3Bupdate-initramfs: deferring update (hook will be called later)
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/dkms 3.5.0-25-generic /boot/vmlinuz-3.5.0-25-generic
**Error! Your kernel headers for kernel 3.5.0-25-generic cannot be found.
Please install the linux-headers-3.5.0-25-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.5.0-25-generic /boot/vmlinuz-3.5.0-25-generic**
update-initramfs: Generating /boot/initrd.img-3.5.0-25-generic
run-parts: executing /etc/kernel/postinst.d/pm-utils 3.5.0-25-generic /boot/vmlinuz-3.5.0-25-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 3.5.0-25-generic /boot/vmlinuz-3.5.0-25-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 3.5.0-25-generic /boot/vmlinuz-3.5.0-25-generic
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.5.0-25-generic
Found initrd image: /boot/initrd.img-3.5.0-25-generic
Found linux image: /boot/vmlinuz-3.5.0-17-generic
Found initrd image: /boot/initrd.img-3.5.0-17-generic
Found memtest86+ image: /boot/memtest86+.bin
Found Windows 7 (loader) on /dev/sda1
Found Ubuntu 12.10 (12.10) on /dev/sda6
Found Ubuntu 12.04.1 LTS (12.04) on /dev/sda7
done
Setting up linux-image-extra-3.5.0-25-generic (3.5.0-25.39) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/dkms 3.5.0-25-generic /boot/vmlinuz-3.5.0-25-generic
Error! Your kernel headers for kernel 3.5.0-25-generic cannot be found.
Please install the linux-headers-3.5.0-25-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.5.0-25-generic /boot/vmlinuz-3.5.0-25-generic
update-initramfs: Generating /boot/initrd.img-3.5.0-25-generic
run-parts: executing /etc/kernel/postinst.d/pm-utils 3.5.0-25-generic /boot/vmlinuz-3.5.0-25-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 3.5.0-25-generic /boot/vmlinuz-3.5.0-25-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 3.5.0-25-generic /boot/vmlinuz-3.5.0-25-generic
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.5.0-25-generic
Found initrd image: /boot/initrd.img-3.5.0-25-generic
Found linux image: /boot/vmlinuz-3.5.0-17-generic
Found initrd image: /boot/initrd.img-3.5.0-17-generic
Found memtest86+ image: /boot/memtest86+.bin
Found Windows 7 (loader) on /dev/sda1
Found Ubuntu 12.10 (12.10) on /dev/sda6
Found Ubuntu 12.04.1 LTS (12.04) on /dev/sda7
done
Setting up linux-image-generic (3.5.0.25.31) ...

Best Answer

Try this:

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