Linux version can be checked using inbuilt commands or can read from specific files. It is important to determine the distribution name and version on many occasion like when doing package updates or OS update.
There are a lot of Linux distributions available like Debian, Ubuntu, CentOS, Mint, Arch, Fedora, RHEL, and more.
In this tutorial, I will show how to check the Linux version from the command line.
Check Linux Version
There are mainly 5 ways we can get Linux distribution name and its version.
01) From /etc/os-release
Use cat command to read the content of the file /etc/os-release
, run the following command:
Output from CentOS # cat /etc/os-release NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7"
Output from Ubuntu $ cat /etc/os-release NAME="Ubuntu" VERSION="18.04.4 LTS (Bionic Beaver)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 18.04.4 LTS" VERSION_ID="18.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=bionic UBUNTU_CODENAME=bionic
02) Using lsb_release command
The lsb_release -a displays the Linux version information from the command line. The output will display distribution ID, description, release and codename. To display only the description you can use lsb_release -d
.
If you get "command not found" and then you need to install 'lsb-core' package.
Output $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.1 LTS Release: 18.04 Codename: bionic
To display only the description, run:
$ lsb_release -d Description: Ubuntu 18.04.4 LTS
03) Using Hostnamectl command
In modern Linux distributions which use systemd init systems, you can use hostnamectl
command to display operating system version, run:
$ hostnamectl Static hostname: linoxide Icon name: computer-vm Chassis: vm Machine ID: cb018d6767ca4c8983df25647a8794b0 Boot ID: ac9d219352a94cdba47494ebd1f42f5c Virtualization: kvm Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-862.11.6.el7.x86_64 Architecture: x86-64
04) From /etc/issue file
You can get version information from /etc/issue
file, to read file content use cat or less command:
$ cat /etc/issue
Output Ubuntu 18.04.4 LTS \n \l
05) From /etc/*release or /etc/*version
Some distribution use release
and version
file and those files are specific to that distro.
$ echo /etc/*version /etc/*release
/etc/debian_version /etc/ec2_version /etc/lsb-release /etc/os-release
To read the content from /etc/*release or /etc/*version, run the following command:
$ cat /etc/*release
$ cat /etc/*version
Some outputs:
If you are interested to know the Linux kernel version and architecture then use uname command or you can read the content from /proc/version
file.
Sample output
$ cat /proc/version Linux version 3.10.0-862.11.6.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) ) #1 SMP Tue Aug 14 21:49:04 UTC 2018
$ uname -srm Linux 3.10.0-862.11.6.el7 x86_64
Conclusion
In this tutorial, we learned different ways to find Linux OS name and version from I hope you enjoyed reading and please leave your suggestion in the below comment section.