Checking Version of Ubuntu Using /etc/os-release special file
cat command in Linux is used to display the content of one or more files present in your machine. It can also be used to create new files and add content to them at creation. To view a file content using the cat command, use the below syntax:
Type following command on the terminal:
Here is the output from our system as an example:
NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 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 special file system in Linux, and Ubuntu may appear to be magical. You can cat or read files and obtain dynamic information from the file supplied by the linux kernel. Some magic files also support writing to them and sending commands to the linux kernel this way. The beauty of linux is everything is a file.
Checking Ubuntu Version Using lsb_release Utility
The lsb_release utility displays the LSB (Linux Standard Base) information about the Linux distribution. lsb_release provides LSB (Linux Standard Basis) information for the Linux distribution is a nice technique for checking your Ubuntu release and should work on other linux distributions as well.
Try running this command:
Here is the output from lsb_release -a on our system we are using today:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.5 LTS
Release: 20.04
Codename: focal
We supplied -a command line to lsb_release which indicates to provide all available information. You can also try the -r command line option for more compact output. Try this command:
Here is the output from lsb_release -a on our system we are using today:
Release: 20.04
Checking Ubuntu Version Using hostnamectl Command
Although hostnamectl command is designed to manage the system hostname, it provides a neat and cool way to obtain the Operating system information and some other vital stats like system architecture, hardware, and Kernel information. Its worth trying it. Type the command with no parameters, root not needed, as follows on the command line:
Here are the details displayed form the system we ran it on below, yours will reflect your system:
Static hostname: linux1
Icon name: computer-vm
Chassis: vm
Machine ID: 33247a0b109245669aa887b7c280f82a
Boot ID: 7f2a5668c4bd4c4d97c37f3c1a2d1be5
Virtualization: vmware
Operating System: Ubuntu 22.04.1 LTS
Kernel: Linux 5.15.0-56-generic
Architecture: x86-64
Hardware Vendor: VMware, Inc.
Hardware Model: VMware Virtual Platform
sysads@linux1:~$
You can see some interesting data you can use for system admin or devops scripts in the output of hostnamectl command.
Checking the Ubuntu Version Using GUI
This article is about command line, but if you want to use the GUI, just search for About tab in Settings application in the GUI search. Here is the output similar to what you can expect:
Conclusion
We have seen multiple ways to check the version of your Ubuntu OS from the command line and also the GUI. It is good to be aware of your environment including the OS version for many reasons including security and accuracy of all your operations.