Let’s look at how to update the Linux kernel to the latest version in CentOS as an example.
Check which version of Linux you have installed:
$ cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)
Check the kernel version:
$ uname -r
4.18.0-193.6.3.el8_2.x86_64
The kernel version 4.18 is quite old and we will update it to 5.17.
Let’s start by connecting the ElRepo repository. This is a community repository for Enterprise Linux which provides support for RHEL, CentOS, Scientific, and Fedora.
Import the repository key:
$ rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
And install ElRepo:
$ dnf install -y https://www.elrepo.org/elrepo-release-8.el8.elrepo.noarch.rpm
List available Linux kernels:
$ dnf --disablerepo="*" --enablerepo="elrepo-kernel" list available| grep kernel-ml
To install the latest available kernel, use the command:
$ dnf --enablerepo=elrepo-kernel install kernel-ml
Now you need to configure Linux to boot with the new kernel:
$ grub2-set-default 0
Update the grub config:
$ grub2-mkconfig -o /boot/grub2/grub.cfg
Restart your host:
reboot
Check the kernel version and make sure it has changed to 5.17:
$ uname -r
5.17.1-1.el8.elrepo.x86_64
Two versions of the kernel are currently available on the system:
$ rpm -qa | grep kernel
kernel-core-4.18.0-240.10.1.el8_3.x86_64 kernel-ml-core-5.17.1-1.el8.elrepo.x86_64
You can remove the old kernel (optional):
$ dnf remove kernel-core-4.18.0 kernel-devel-4.18.0 kernel-tools-libs-4.18.0 kernel-headers-4.18.0
Check that the old kernel version has been removed:
$ rpm -qa | grep kernel
kernel-ml-core-5.17.1-1.el8.elrepo.x86_64 kernel-ml-5.17.6-1.el8.elrepo.x86_64 kernel-ml-modules-5.17.1-1.el8.elrepo.x86_64