blog posts

How to check your Linux version?

Those new users of the Linux operating system have the question of how to determine the version of Linux. Various distributions of Linux have the Linux kernel, GNU tools and libraries, and other software packages preinstalled.

People who are new to Linux may not be familiar with the code that comes with Windows version detection. Knowing the Linux version is necessary for security patches and package management for installing new packages.

Users’ common versions include: Debian, Ubuntu, Fedora, Arch Linux, Red Hat, CentOS, etc. am). Knowing the version and name of the operating system can be useful for security patches; Additionally, you can find out which package manager to use to install new packages.

In the article, the most used Linux commands for beginners, we have brought useful commands to run in the Linux operating system. Still, in this article, we want to tell you some commands that you can easily identify the Linux version of your operating system. So if you don’t know your Linux version, stay with us in this article.

Easy detection of Linux version through 5 commands

There are various commands to check it which we explain step by step.

cat /etc/os-release for easy Linux version detection

You can use the following code to determine the Linux version.

cat /etc/os-release

The output it gives is as follows:

NAME=”Ubuntu”
VERSION=”20.04.1 LTS (Focal Fossa)”
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME=”Ubuntu 20.04.1 LTS”
VERSION_ID=”20.04″
HOME_URL=”https://www.ubuntu.com/”
SUPPORT_URL=”https://help.ubuntu.com/”
BUG_REPORT_URL=”https://bugs.launchpad.net/ubuntu/”
PRIVACY_POLICY_URL=”https://www.ubuntu.com/legal/terms-and-policies/privacy-policy”
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

We can filter information such as OS version and name using the grep/grep command as follows:

grep '^VERSION' /etc/os-release $ egrep '^(VERSION|NAME)=' /etc/os-release

What we will see:

NAME=”CentOS Linux” VERSION=”8 (Core)”

Even small Linux distributions like Alpine Linux provide the operating system (OS) information required, including:

NAME=”Alpine Linux”
ID=alpine
VERSION_ID=3.12.1
PRETTY_NAME=”Alpine Linux v3.12″
HOME_URL=”https://alpinelinux.org/”
BUG_REPORT_URL=”https://bugs.alpinelinux.org/”

Checking the Linux version using the lsb_release command

The lsb_release tool provides you with all the information related to LSB (Linux Standard Base). This command runs on Linux distributions that have the lsb_release package installed.

If lsb_release is not installed on your system, then you need to install it, for this you can use apk command in Alpine Linux, dnf command/yum command in RHEL & co, apt/apt-get command in Debian, Ubuntu and co, zypper command in SUSE/OpenSUSE, pacman command in Arch Linux.

After you have installed it, use the following command:

lsb_release –a

The output that this code gave us is as follows:

LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.4.1708 (Core)
Release: 7.4.1708
Codename: Core

Easy detection of Linux version with hostnamectl command

Use the hostnamectl command to check and change the system hostname and related settings. Just type the following command to check the operating system name and Linux kernel version. For example:

hostnamectl

The output that this command gives you is as follows:

Static hostname: nixcraft-www-42
Icon name: computer-vm
Chassis: vm
Machine ID: beb217fbb4324b7d9959f78c279e6599
Boot ID: 10f00cc5ca614b518a84d1793d0134bc
Virtualization: qemu
Operating System: Ubuntu 16.04.3 LTS
Kernel: Linux 4.10.0-42-generic
Architecture: x86-64

Another output from OpenSUSE Linux Server 15.2

Static hostname: opensuse-nixcraft
Icon name: computer-vm
Chassis: vm
Machine ID: b95459dbd45d428fa513ab6a9636d1a8
Boot ID: 9a144556789241e29b62b962cfb6ba1d
Virtualization: kvm
Operating System: openSUSE Leap 15.2
CPE OS Name: cpe:/o:opensuse:leap:15.2
Kernel: Linux 5.3.18-lp152.50-default
Architecture: x86-64

Easy detection of Linux version with uname command

With the help of the uname command, you can only find out your Linux kernel version:

uname -r

The output you see in the image below is obtained with the help of this command:

Using the file /etc/*release

If none of the commands and items mentioned above worked for you, you are likely using an old or even outdated Linux distribution. If this is the case for you, running one of the following commands can show you the contents of the distribution version or version file:

cat /etc/*release

cat /etc/*version

Conclusion

As we promised, we have provided you with 5 of the easiest ways to detect the Linux version. If you have any questions or know a better way, share it with us in the comments section.