Check Ubuntu Version

Check Ubuntu Version

Finding out which Ubuntu version is running on the machine can be useful when troubleshooting problems or installing software.

This tutorial shows how to check Ubuntu version.

1. lsb_release command

The lsb_release command displays LSB (Linux Standard Base) and distribution information. This command can be used to determine Ubuntu version.

lsb_release -a

The output of the command will look like this:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:        20.04
Codename:       focal

The -a option prints all information. Ubuntu version can be determined only from description. It can be displayed with -d option. The following command prints only Ubuntu version:

lsb_release -d | grep -Po "[0-9.]+"

Output:

20.04.2

2. /etc/lsb-release file

The /etc/lsb-release file holds information about distribution. It can be used to determine Ubuntu version.

cat /etc/lsb-release

Output:

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.2 LTS"

Command to get only Ubuntu version:

cat /etc/lsb-release | grep DESCRIPTION | grep -Po "[0-9.]+"

3. /etc/os-release file

The /etc/os-release file contains operating system identification data. This file allows to determine Ubuntu version.

cat /etc/os-release

Output:

NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 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

The following command displays only Ubuntu version:

cat /etc/os-release | grep PRETTY_NAME | grep -Po "[0-9.]+"

4. /etc/issue file

The /etc/issue file stores a system identification text which is printed after log in to the system.

cat /etc/issue

Output:

Ubuntu 20.04.2 LTS \n \l

Extract only Ubuntu version:

cat /etc/issue | grep -Po "[0-9.]+"

5. hostnamectl command

The hostnamectl command allows to get or set the system hostname. This command also can be used to determine Ubuntu version.

hostnamectl

Output:

Static hostname: ubuntu
       Icon name: computer-vm
         Chassis: vm
      Machine ID: 089a75bffe4b4921b2f971cc7f94f47f
         Boot ID: 5872113106b841b7b9ef6a003f2f9dc0
  Virtualization: vmware
Operating System: Ubuntu 20.04.2 LTS
          Kernel: Linux 5.4.0-72-generic
    Architecture: x86-64

Run the following command to get only Ubuntu version:

hostnamectl | grep System | grep -Po "[0-9.]+"

Leave a Comment

Cancel reply

Your email address will not be published.