How to Upgrade Kernel on CentOS 7

The Kernel is the brain for an operating system. It's like the core element of every OS. Speaking of Linux, the Linux kernel - created by Linus Torvalds - is a monolithic, Unix-like kernel. Some popular OSs that use the Linux kernel are Ubuntu, CentOS, and Debian.

In this tutorial, I will show you how to upgrade CentOS 7 kernel to the latest version, and we will be using the kernel from ELRepo repository. CentOS 7 is using 3.10 as the default kernel version. And in this guide, we will install the latest stable version 4.11.2.

What is ELRepo?

ELRepo is a community-based repository for Enterprise Linux and offers support for RedHat Enterprise (RHEL) and other distribution based on it (CentOS, Scientific, Fedora etc).

ELRepo is focused on the packages related to hardware, including filesystem drivers, graphic drivers, network drivers, sound card drivers, webcam, and others.

What we will do

  1. Update and upgrade CentOS 7
  2. Checking kernel version
  3. Add ELRepo repository
  4. Install new kernel version
  5. Configure Grub2
  6. Remove old kernel

Step 1 - Update and upgrade CentOS 7

The first thing we must do before upgrading the kernel is to upgrade all packages to the latest version. Update the repository and all packages to latest versions with the yum command below.

yum -y update

Now install the following package to make installation and updating process fast.

yum -y install yum-plugin-fastestmirror

CentOS 7 System updated and all packages upgraded to latest versions.

Step 2 - Checking kernel version

In this tutorial, we will use CentOS 7.3 with default kernel 3.10. Check your CentOS version with the following commands.

cat /etc/redhat-release
cat /etc/os-release

You will get the system info as shown below.

For checking the kernel version, you can use the uname command.

uname -msr

The output will show your machine's Linux kernel version as well system architecture.

Step 3 - Add ELRepo Repository

Before installing new kernel version, we need to add new repository ELRepo repository. That's because we want to use the kernel version from the ELRepo community.

Add ELRepo gpg key to the system.

rpm --import

Now add new ELRepo repository with rpm command.

rpm -Uvh

Next, check all repositories enabled on the system, and make sure ELRepo is on the list.

yum repolist

ELRepo repository has been added to the CentOS 7 server.

Step 4 - Install new Kernel version

In this step, we will install latest kernel version (4.11.2 - the Latest stable version on from the ELRepo repository.

Use the following yum command for this.

yum --enablerepo=elrepo-kernel install kernel-ml

--enablerepo is an option to enable specific repository on CentOS system. By default, 'elrepo' repository is enabled, but for our case, we needed 'elrepo-kernel'.

You can check all of the available repositories on the system (enabled as well as disabled) with the following command.

yum repolist all

Step 5 - Configure Grub2 CentOS 7

At step 4, we've already installed a new kernel 4.11.2 to the system. Now we will show you how to make it the default kernel version that will load when the system is starting.

Check all available kernel versions with the awk command below.

sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg

In the output, you'll see that we've two kernel versions - 3.10 and 4.11.2.

We want to use kernel 4.11 as our default, so you can use the following command to make this happen.

sudo grub2-set-default 0

0 - it's from the awk command on the top. Kernel 4.11.2 = 0, and Kernel 3.10 = 1. When you want to revert back to the old kernel, you can change the value of the grub2-set-default command to 1.

Next, generate the grub2 config with 'gurb2-mkconfig' command, and then reboot the server.

sudo grub2-mkconfig -o /boot/grub2/grub.cfg
sudo reboot

Please login to the server again, and check currently used kernel.

uname -msr

The result should be that the kernel version 4.11.2 is being used on your system.

Step 6 - Remove old kernel (optional)

This is an optional step that we think you need in order to get more free space. In this step, we will show you how to remove an old kernel from your CentOS 7 system. This can be done when you have several kernel versions installed on the server.

For this purpose, we need to install the yum-utils utility from the repository.

yum install yum-utils

Now clean your old kernel with the following command.

package-cleanup --oldkernels

If you get the result below.

That means you've only 2 or 3 versions of kernel installed. If you have more than 3 version installed, the command will automatically remove old kernel from your system.

CentOS 7 Kernel has been updated to the latest stable using ELRepo kernel version.


Share this page:

Suggested articles

14 Comment(s)

Add comment


By: Andy at: 2018-08-22 13:59:54

How to install headers and devel for Kernel 4.18? How to uninstall 3.10 headers?

By: Andy at: 2018-08-22 18:47:15

Considering this URL to answer my question:

By: Andrew at: 2019-01-19 01:10:37

Thanks!!!! that's the other part I needed for my install.


And thanks Muhammad Arul for the origional writeup!!!

By: asysliasa at: 2019-04-05 23:07:10

With this everything is done :D Thank you

By: scorpio at: 2018-09-09 15:28:34

Thanks for the above instruction, you did a good job telling us how, but for what reason would we want to upgrade?

By: till at: 2018-09-10 10:04:20

A Kernel upgrade might be required when you want to use new hardware that the old kernel does not support or when you need functions that are not available in the old Kernel.

By: chris at: 2018-11-30 13:11:59

Thanks for the above instructions.


By: Michael at: 2018-12-05 21:47:01

Thank you! Very useful information and steps. In Step 3, where it has the following, check first in for more updated release

rpm -Uvh

By: Rea at: 2019-02-17 18:51:51

Thank you for the writeup ... I tried but I get the error: [[email protected] ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfgawk: fatal: cannot open file `/etc/grub2.cfg' for reading (No such file or directory)#

/boot is empty except for the ElRepo files and the two empty folders grub2 and efi

I thought in /boot there should be a config file?

Can you help?

By: Pedro Salazar at: 2019-03-01 05:50:38

Thanks my friend, Hello from Venezuela

By: raiden at: 2019-04-21 09:40:25

I am stuck at step 5, my linux doesn't have any boot loader intalled

By: Ralph at: 2019-04-25 12:16:35

Thanks for the instructions. Slight type here though: "Next, generate the grub2 config with 'gurb2-mkconfig' command, and then reboot the server."

By: Hasan at: 2019-05-16 18:15:35

Hi Guys,

Need your help urgently, I tried following the instruction given above and  the server is not booting now. The grub.cfg file is corrputed. 


[[email protected] bin]# grub2-mkconfig -o /boot/grub2/grub.cfg

No path or device is specified. Usage: grub2-probe [OPTION...] [OPTION]... [PATH|DEVICE] Try 'grub2-probe --help' or 'grub2-probe --usage' for more information. No path or device is specified. Usage: grub2-probe [OPTION...] [OPTION]... [PATH|DEVICE] Try 'grub2-probe --help' or 'grub2-probe --usage' for more information. No path or device is specified. Usage: grub2-probe [OPTION...] [OPTION]... [PATH|DEVICE] Try 'grub2-probe --help' or 'grub2-probe --usage' for more information.

By: trevor getty at: 2019-07-02 16:29:53

The epel link for the 7.0.2 elrepo is now longer valid. If you try that link, it now contains a redirect which will not be followed by the rpm command. Instead use: