What Linux Version Am I Using ?

This may seem like a question you would already know the answer to, but when you are connecting to Linux systems via SSH rather than interacting with a desktop environment then there are occasions when you may need to check what Linux version you are using. Luckily there are many Linux commands for checking the Linux version installed on your system.

In this article we will explore some of the ways you can check what Linux OS version you are using. If you are looking to check what Linux kernel you have installed then we already covered how to check the Linux kernel version.

Check Linux Version using hostnamectl

hostnamectl is a great tool for displaying information about your Linux system. Let’s take a look at it’s output:

$ hostnamectl
   Static hostname: 7439916afd1c.local
         Icon name: computer-vm
           Chassis: vm
        Machine ID: ec2d66dbb104b22
           Boot ID: 2289fa54e1ab42438f
    Virtualization: kvm
  Operating System: Ubuntu 20.04.3 LTS
            Kernel: Linux 5.11.0-1025-aws
      Architecture: x86-64

I like this tool as along with the Linux Operating System version (Ubuntu 20.94), we are also given other useful information including the Linux Kernel version, the system architecture, the hostname and in this example, details that this is a virtual machine running on kvm. Lot’s of useful information here!

Hostnamectl also allows you to check the Linux version of a remote host, using the following syntax:

-H --host=[USER@]HOST  Operate on remote host

Check Linux Version using lsb_release

The lsb_release command prints distribution specific information.

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.3 LTS
Release:	20.04
Codename:	focal

As you can see, the information here is only focused on information on the version of the Linux operating system installed. The output gives information on the OS distributor ID, the release and the codename for the release. In this case it is Ubuntu 20.04 Focal.

/etc/os-release

Another place where you can check your Linux version is the /etc/os-release file. This is a line separated file which contains operating system identification data. Let’s have a look at it’s contents:

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.3 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

There is a lot of information about the Linux distribution here, including the name and version of the operating system and links to the website for the OS. Here is another example from a Fedora Linux system:

NAME=Fedora
VERSION="17 (Beefy Miracle)"
ID=fedora
VERSION_ID=17
PRETTY_NAME="Fedora 17 (Beefy Miracle)"
ANSI_COLOR="0;34"
CPE_NAME="cpe:/o:fedoraproject:fedora:17"
HOME_URL="https://fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

As this is a text file it is easy to query programmatically.

Summary

In this short article you have learned a number of different ways to check the version of Linux you are running on a local or remote system. We have looked at how the hostnamectl and lsb_release commands can be used to output Linux version details. Finally, we talked about the os-release file.

Related posts

Mastering the Linux ifconfig Command

Docker Exec Command With Practical Examples

Debugging with Git Bisect

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More