I most often use the following command to find out the version of Linux on the host:
# lsb_release –a
No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 11 (bullseye) Release: 11 Codename: bullseye
This command is part of the lsb-core package, which is installed by default on Ubuntu and Debian.
For rpm-based Linux distros (RHEL, CentOS, Rocky/Oracle Linux), you can find the OS version and name as follows:
# cat /etc/*rel*
CentOS Linux release 7.9.2009 (Core)
You can use the uname
command to display the processor architecture and kernel version on less common Linux distributions:
# uname -a
The output of this command also contains the Linux version.
As you can see, there are different commands that are used to determine the version of Linux in different distros.
On Linux versions with systemd (is used in most modern distributions), you can use the universal command to find out the OS version:
$ hostnamectl
Static hostname: appsrvub1 Icon name: computer-vm Chassis: vm Machine ID: 6a63d206dac44f89aa9c27b5b95bbc3e Boot ID: fe3420171e31452e8449dda7f46e7cc4 Virtualization: vmware Operating System: Ubuntu 22.04.1 LTS Kernel: Linux 5.15.0-56-generic Architecture: x86-64 Hardware Vendor: VMware, Inc. Hardware Model: VMware Virtual Platform
This command works in the same way on all the platforms. It also instantly shows which platform Linux is running on: container, VM, or hardware.