The Ubuntu operating system is a good alternative for Windows and macOS users. It is an open-source operating system available free to all. While working, we need to install multiple third-party software, which is available for version-specific. In that case, you need to find the Ubuntu version you are using.
The lsb-release is the standard package for reporting the version on Ubuntu systems. Which is basically written in the Python programming language. It provides lsb_release command-line tool to check Ubuntu version and other useful details.
In this tutorial, you will learn various options to get the Ubuntu version details with the command line. Also provide you instructions to check the Ubuntu version in Shell scripts, which will help to make the version-specific script.
How to Check Ubuntu Version
Here are 4 methods to find the Ubuntu version:
Method 1: Check Ubuntu version in /etc/lsb-release File
The /etc/lsb-release
is the main file, which contains the Ubuntu version details. You can view /etc/lsb-release file content to fine Ubuntu version and version-specific details.
Open a terminal on your system and type:
cat /etc/lsb-release
Method 2: Check Ubuntu version with lsb-release Command
Alternativeally, Use lsb-release
command to view Ubuntu version details. This utility also reads the content from /etc/lsb-relese file.
Run the lsb_release command with -a
option to view all details.
lsb_release -a
The above output shows that your system is running with Ubuntu 22.04 LTS system and the codename is focal.
Method 3: Check Ubuntu version with hostnamectl Command
The hostnamectl
command is used to query and change the system’s hostname and related settings. The output also shows the Ubuntu version details.
hostnamectl
Method 4: Check Ubuntu Version with GUI
Login to the graphical interface >> Open settings >> click About in sidebar. Here you will find the Ubuntu server version with other system details.
Check Specific Details
You can also use other command-line options to fetch specific details about the Ubuntu versions. Use the following commands on the terminal to view specific Ubuntu version details.
- View distribution name
lsb_release -i
## Output: "Distributor ID: Ubuntu" lsb_release -is
## Output: "Ubuntu" - Show the Ubuntu version description
lsb_release -d
## Output: "Description: Ubuntu 22.04 LTS" lsb_release -ds
## Output: "Ubuntu 22.04 LTS" - Show the release number version
lsb_release -r
## Output: "Release: 22.04" lsb_release -rs
## Output: "22.04" - View Ubuntu codename
lsb_release -c
## Output: "Codename: jammy" lsb_release -cs
## Output: "jammy"
When using the -s
parameter in above commands shows the short version output. That is helpful with shell scripting.
How to Find Ubuntu Version in a Shell Script
Shell scripts play an important role in system administration tasks. They help us to automate tasks easily. While writing shell scripts, you may be required to check the Ubuntu version details before executing a set of commands. Here is a sample shell script to check the Ubuntu version to run a set of commands.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #!/bin/bash code=$(lsb_release -cs) if [ $code == "jammy" ]; then echo "You are running Ubuntu 22.04" elif [ $code == "focal" ]; then echo "You are running Ubuntu 20.04" elif [ $code == "bionic" ]; then echo "You are running Ubuntu 18.04" elif [ $code == "xenial" ]; then echo "You are running Ubuntu 16.04" else echo "No matching version found" fi |
Ubuntu Release Cycle
Ubuntu release a new version every 6 months. All the Ubuntu version numbers follow the “YY:MM” format. For example, the last release of Ubuntu is 21.04 (Apr 2021).
Every 2 years a Long Term Support (LTS) version is released by the team, which supports updates for the next 5 years. All the production servers are suggested to use the LTS version as its most stable release.
Recent Ubuntu Versons:
- Ubuntu 22.04 LTS
- Ubuntu 21.10
- Ubuntu 21.04
- Ubuntu 20.10
- Ubuntu 20.04 LTS
- Ubuntu 19.10
- Ubuntu 19.04
- Ubuntu 18.10
- Ubuntu 18.04 LTS
Conclusion
This tutorial described how to find running Ubuntu system version details on the command line. Also provides instructions to verify the version before running commands in shell scripts.