Skip to main content
How To

How to Check Ubuntu Version in Command Line

Learn how to know the Ubuntu version number and release codename in the command line.

Abhishek

Knowing your Ubuntu version is helpful in several situations. If you are adding an external repository for additional packages or if you want to know whether a certain program version is available for your Ubuntu install or not. Or, if you simply seeking help in Linux forums and you need to provide the information on your Ubuntu version.

Whatever may be the reason, it's always good to know the basic information about the system you are using.

How to check Ubuntu version?  

The easiest way to check the Ubuntu version is to use the following command in the terminal:

lsb_release -a

This gives all the necessary distributions specific information.

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04 LTS
Release:	22.04
Codename:	jammy

You can see the Ubuntu version in the Description or Release line. As you can see in the output above, I am using Ubuntu version 22.04 which is codenamed 'jammy'.

This codename is also useful, especially when you are adding an external repository that needs the codename of the Ubuntu release.

Checking Ubuntu version using ls_release -a command

Now that you know how to show Ubuntu version in CLI, let me share a handy tip.

MEGA
MEGA provides free cloud storage with convenient and powerful always-on privacy. Claim your free 20GB now

Check how long your system is supported

The LTS in the description means that this is a long-term support (LTS) release. The LTS release is supported for five years from its release. You can see how long your current Ubuntu system will be supported with the following command:

ubuntu-security-status
Checking Ubuntu support status in command line

As you can see in the screenshot above, my Ubuntu system is supported till April 2027 (4/2027).

Get only the Ubuntu version or release name

The command lsb_release -a gives you 5 lines of output in two columns.

It's not convenient to use this information in a script or command. The good thing here is that you don't need to do any ninja stuff to format the output with grep and cut command. There is a shorter version to give you the exact necessary detail.

To get just the Ubuntu version number, combine the s (short) and d (description) options:

lsb_release -ds

Similarly, to get just the Ubuntu codename, combine the s and c (codename) options:

lsb_release -cs

You can see the outputs in the screenshot below:

Get only the version number and codename of Ubuntu releases

This is more appropriate to be used in the scripts, right?

Other ways to check Ubuntu version

While lsb_release -a is my preferred way to get the Ubuntu version details; it's not the only way. There are other commands that provide you with this information.

You can use the hostnamectl command:

hostnamectl

You can see the Ubuntu version detail in the output but no codename:

Static hostname: learnubuntu
       Icon name: computer-vm
         Chassis: vm
      Machine ID: c022d7fa917ec36bb318f777628c6940
         Boot ID: a2fe9f564a424550bf5db043ce94bdce
  Virtualization: kvm
Operating System: Ubuntu 22.04 LTS                
          Kernel: Linux 5.15.0-25-generic
    Architecture: x86-64
 Hardware Vendor: DigitalOcean
  Hardware Model: Droplet

You get additional details such as whether it's a physical or virtual system, kernel version, and CPU architecture. From the output, you can surmise that I am using a VM on DigitalOcean.

DigitalOcean – The developer cloud
Helping millions of developers easily build, test, manage, and scale applications of any size – faster than ever before.

Another way to get the Ubuntu version detail is to read the content of file /etc/os-release:

cat /etc/os-release

This gives plenty of information in addition to the codename and version name:

PRETTY_NAME="Ubuntu 22.04 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04 (Jammy Jellyfish)"
VERSION_CODENAME=jammy
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=jammy

So, you learned various ways to find the version of Ubuntu installed on your system. The command-line methods work everywhere, be it Ubuntu running in WSL or AWS.

Let me know if you have any questions.