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 24.04 LTS
Release:        24.04
Codename:       noble

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:

24.04

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=24.04
DISTRIB_CODENAME=noble
DISTRIB_DESCRIPTION="Ubuntu 24.04 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:

PRETTY_NAME="Ubuntu 24.04 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
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"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo

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 24.04 LTS \n \l

Extract only Ubuntu version:

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

5. hostnamectl command

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

hostnamectl

Output:

 Static hostname: ubuntu
       Icon name: computer-vm
         Chassis: vm 🖴
      Machine ID: 6a64daca76de4312a120b636f3deb95b
         Boot ID: d1837b5fd75343d2836cf6875b3e213a
  Virtualization: vmware
Operating System: Ubuntu 24.04 LTS
          Kernel: Linux 6.8.0-31-generic
    Architecture: x86-64
 Hardware Vendor: VMware, Inc.
  Hardware Model: VMware Virtual Platform
Firmware Version: 6.00
   Firmware Date: Thu 2020-11-12
    Firmware Age: 3y 5month 2w 4d

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.