How to install the latest/stable version of Linux kernel on Ubuntu Linux using apt-get

Posted on in Categories , last updated July 23, 2017

I read your tutorial about compiling a stable version of the Linux kernel on a Ubuntu/Debian Linux. I wanted to install the same using apt-get command. How can I install the latest (mainline) Linux kernel on Ubuntu Linux?

Installing a brand new kernel on server or desktop is not recommended. The latest version might be buggy and can crash your system. However, if you need the latest version try the following instructions.

Method #1: Search and install the latest stable version

I tested this method on the following version of Ubuntu:

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.2 LTS
Release:	16.04
Codename:	xenial

To find out your current version of Linux kernel, run:
$ uname -mrs
Linux 4.4.0-83-generic x86_64

To find out the latest version of Linux kernel type:
$ apt-cache search linux-generic
Sample outputs:

linux-generic - Complete Generic Linux kernel and headers
linux-generic-lts-utopic - Complete Generic Linux kernel and headers (dummy transitional package)
linux-generic-lts-vivid - Complete Generic Linux kernel and headers (dummy transitional package)
linux-generic-lts-wily - Complete Generic Linux kernel and headers (dummy transitional package)
linux-generic-lts-xenial - Complete Generic Linux kernel and headers (dummy transitional package)
linux-image-4.4.0-21-generic - Linux kernel image for version 4.4.0 on 64 bit x86 SMP
linux-image-extra-4.4.0-21-generic - Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
linux-generic-hwe-16.04 - Complete Generic Linux kernel and headers
linux-generic-hwe-16.04-edge - Complete Generic Linux kernel and headers
linux-image-4.10.0-14-generic - Linux kernel image for version 4.10.0 on 64 bit x86 SMP
linux-image-4.10.0-19-generic - Linux kernel image for version 4.10.0 on 64 bit x86 SMP
linux-image-4.10.0-20-generic - Linux kernel image for version 4.10.0 on 64 bit x86 SMP
linux-image-4.10.0-21-generic - Linux kernel image for version 4.10.0 on 64 bit x86 SMP
linux-image-4.10.0-22-generic - Linux kernel image for version 4.10.0 on 64 bit x86 SMP
linux-image-4.10.0-24-generic - Linux kernel image for version 4.10.0 on 64 bit x86 SMP
linux-image-4.10.0-26-generic - Linux kernel image for version 4.10.0 on 64 bit x86 SMP
linux-image-4.10.0-27-generic - Linux kernel image for version 4.10.0 on 64 bit x86 SMP
linux-image-4.4.0-22-generic - Linux kernel image for version 4.4.0 on 64 bit x86 SMP
linux-image-4.4.0-24-generic - Linux kernel image for version 4.4.0 on 64 bit x86 SMP
linux-image-4.4.0-28-generic - Linux kernel image for version 4.4.0 on 64 bit x86 SMP
linux-image-4.4.0-31-generic - Linux kernel image for version 4.4.0 on 64 bit x86 SMP

The highest possible version is 4.10.0-27. To install it just type the following apt-get command/apt command:
$ sudo apt install linux-image-4.10.0-27-generic
OR
$ sudo apt-get install linux-image-4.10.0-27-generic
Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-81 linux-headers-4.4.0-81-generic linux-image-4.4.0-81-generic
Use 'apt autoremove' to remove them.
Suggested packages:
  fdutils linux-tools linux-headers-4.10.0-27-generic
The following NEW packages will be installed:
  linux-image-4.10.0-27-generic
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/20.1 MB of archives.
After this operation, 70.0 MB of additional disk space will be used.
Selecting previously unselected package linux-image-4.10.0-27-generic.
(Reading database ... 89746 files and directories currently installed.)
Preparing to unpack .../linux-image-4.10.0-27-generic_4.10.0-27.30~16.04.2_amd64.deb ...
Done.
Unpacking linux-image-4.10.0-27-generic (4.10.0-27.30~16.04.2) ...
Setting up linux-image-4.10.0-27-generic (4.10.0-27.30~16.04.2) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.10.0-27-generic /boot/vmlinuz-4.10.0-27-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.10.0-27-generic /boot/vmlinuz-4.10.0-27-generic
update-initramfs: Generating /boot/initrd.img-4.10.0-27-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.10.0-27-generic /boot/vmlinuz-4.10.0-27-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.10.0-27-generic /boot/vmlinuz-4.10.0-27-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.10.0-27-generic /boot/vmlinuz-4.10.0-27-generic
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /vmlinuz-4.4.0-83-generic
Found kernel: /vmlinuz-4.4.0-81-generic
Found kernel: /vmlinuz-4.10.0-27-generic
Found kernel: /vmlinuz-4.4.0-83-generic
Found kernel: /vmlinuz-4.4.0-81-generic
Replacing config file /run/grub/menu.lst with new version
Updating /boot/grub/menu.lst ... done

You must reboot the Linux server, run:
$ rm *.deb
$ sudo reboot

Verify new version:
$ uname -mrs
Linux 4.10.0-27-generic x86_64

Method #2: Install mainline kernel version v4.12.3

First, if one is using select proprietary or out-of-tree modules (ex. vitualbox, nvidia, fglrx, bcmwl, etc.) unless there is an extra package available for the version you are testing, you will need to uninstall the module first, in order to test the mainline kernel. If you do not uninstall these modules first, then the upstream kernel more than likely will not boot.

First visit kernel.org and note down the latest kernel version:

Fig.01: Note down kernel version
Fig.01: Note down kernel version

Next visit the following url and search for the Linux kernel version 4.12.3
http://kernel.ubuntu.com/~kernel-ppa/mainline/
Fig.02: Downloading the latest build of mainline kernel
Fig.02: Downloading the latest build of mainline kernel

Use the wget command to grab the files:
$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.12.3/linux-headers-4.12.3-041203-generic_4.12.3-041203.201707210343_amd64.deb
$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.12.3/linux-image-4.12.3-041203-generic_4.12.3-041203.201707210343_amd64.deb

To verify the mainline build binaries, run:
$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.12.3/CHECKSUMS
$ sha256sum --ignore-missing -c CHECKSUMS

Sample outputs:

linux-headers-4.12.3-041203-generic_4.12.3-041203.201707210343_amd64.deb: OK
linux-image-4.12.3-041203-generic_4.12.3-041203.201707210343_amd64.deb: OK
sha256sum: WARNING: 23 lines are improperly formatted

You must see OK for all downloaded .deb files. Next, you need to install .deb files using dpkg command:
$ sudo dpkg -i *.deb
You must reboot the Linux server, run:
$ sudo reboot
Verify new version:
$ uname -mrs
Linux 4.12.3-041203-generic x86_64

A note about updating mainline kernel

You must visit and download the latest version from the following url:
http://kernel.ubuntu.com/~kernel-ppa/mainline/
For example, download v4.13-rc1 as follows:
$ rm *.deb
$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.13-rc1/linux-headers-4.13.0-041300rc1-generic_4.13.0-041300rc1.201707151931_amd64.deb
$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.13-rc1/linux-image-4.13.0-041300rc1-generic_4.13.0-041300rc1.201707151931_amd64.deb
$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.12.3/CHECKSUMS
$ sha256sum --ignore-missing -c CHECKSUMS
$ sudo dpkg -i *.deb
$ sudo reboot
$ uname -mrs

This entry is 2 of 2 in the Installing Mainline Linux Kernel on a Ubuntu/Debian series. Keep reading the rest of the series:
  1. How to Compile and Install Linux Kernel From Source Code
  2. How to install mainline Linux kernel on Ubuntu Linux

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

5 comment

  1. Hi,
    About the method #1…
    According to [1] and [2], in order to get a kernel as newer as possible in a most convenient way, you should install “linux-signed-generic-lts-XXX” (e.g., “linux-signed-generic-lts-xenial”) or unsigned version “linux-generic-lts-XXX” (e.g., “linux-generic-lts-xenial”) for Ubuntu before LTS 16.04, even prefer to install the newer “linux-signed-generic-hwe-16.04” or even more bleeding edge “linux-signed-generic-hwe-16.04-edge” for Ubuntu LTS 16.04 and newer; instead of specifying a version of linux kernel image package which won’t be automatically updated via “apt update/upgrade”. In this way, it will keep your kernel up to date as possible.

    Some example commands to find out the proper kernel package name in Ubuntu:

    $ apt-cache search linux-signed-generic-lts
    linux-signed-generic-lts-utopic - Complete Signed Generic Linux kernel and headers (dummy transitional package)
    linux-signed-generic-lts-vivid - Complete Signed Generic Linux kernel and headers (dummy transitional package)
    linux-signed-generic-lts-wily - Complete Signed Generic Linux kernel and headers (dummy transitional package)
    linux-signed-generic-lts-xenial - Complete Signed Generic Linux kernel and headers (dummy transitional package)

    AND
    $ apt-cache search linux-generic-lts
    linux-generic-lts-utopic - Complete Generic Linux kernel and headers (dummy transitional package)
    linux-generic-lts-vivid - Complete Generic Linux kernel and headers (dummy transitional package)
    linux-generic-lts-wily - Complete Generic Linux kernel and headers (dummy transitional package)
    linux-generic-lts-xenial - Complete Generic Linux kernel and headers (dummy transitional package)

    AND
    $ apt-cache search linux-signed-generic-hwe
    linux-signed-generic-hwe-16.04 - Complete Signed Generic Linux kernel and headers
    linux-signed-generic-hwe-16.04-edge - Complete Signed Generic Linux kernel and headers
    $ apt-cache search linux-generic-hwe
    linux-generic-hwe-16.04 - Complete Generic Linux kernel and headers
    linux-generic-hwe-16.04-edge - Complete Generic Linux kernel and headers

    References:
    [1] https://wiki.ubuntu.com/Kernel/LTSEnablementStack
    [2] https://wiki.ubuntu.com/Kernel/RollingLTSEnablementStack

Leave a Comment