How to check OS version in Linux

To check the OS version in Linux can be used for troubleshooting, installing compatible software, or ensuring system compatibility. There are several ways to check the OS version in Linux. In this guide, we’ll cover multiple methods, from using simple command-line tools like `lsb_release` and `uname` to accessing system information through graphical interfaces. Each method provides detailed insights into the Linux version.

Table of Contents

  1. Using os-release file
  2. Using lsb_release command
  3. Using the hostnamectl command
  4. Using the uname command
  5. Using GUI

Method-1: Using os-release file

The os-release file in the /etc directory is a text file that contains information about the operating system (OS) installed on a Linux-based system. It provides essential details such as the OS name, version, and other system-related identifiers, making it useful for scripts or applications that need to detect or configure the system based on its OS.

Key fields found in the os-release file are-

  • NAME: The official name of the OS (e.g., Ubuntu, Fedora, CentOS).
  • VERSION: A description of the OS version (including release number and codename).
  • VERSION_ID: The version number of the OS in a simplified format.
  • ID: A short identifier for the OS, typically a lowercase name.
  • ID_LIKE: Other OS distributions that are similar to the current OS.
  • PRETTY_NAME: A user-friendly version name, often combining the name and version.
  • HOME_URL: URL for the official website of the distribution.
  • SUPPORT_URL: URL for support resources.
  • BUG_REPORT_URL: URL for reporting bugs or issues.
  • CODENAME: The codename of the current OS release.

To view to contents of the os-release file use the command below-

$> cat /etc/os-release
To view to contents of the os-release file use the command below-

To filter out only the Version or the Name and Version of the Operating System from the os-release file use the command below-

$> grep '^VERSION' /etc/os-release
$> grep -E '^(VERSION|NAME)=' /etc/os-release
filter out only the Version or the Name and Version of the Operating System from the os-release file use the command

Method-2: Using lsb_release command

The LSB (Linux Standard Base) is a set of standards that aim to increase compatibility among different Linux distributions. It defines a common set of specifications that Linux distributions should follow to ensure that software developed for one distribution can run on others without modification. The LSB specifies standards for core system libraries, the file system hierarchy, and various command-line utilities.

The LSB defines a tool, lsb_release, which provides a standard way to query the version and other details of a Linux distribution. This tool reads from /etc/os-release or other related configuration files to fetch distribution-specific details. It is commonly used to retrieve information about the OS in a consistent format across different Linux distributions.

Options used with the lsb_release command are-

-a : This option will output detailed information about the distribution, including the distributor ID, description, release version, and codename.

$> lsb_release -a

-d :  This option will output only the name of the distribution.

$> lsb_release -d

-r :  This option will output only the version number of the OS.

$> lsb_release -r

-c :  This option will output only the codename of the distribution.

$> lsb_release -c

-i : This option will output only the name of the distributor.

$> lsb_release -i

Method-3: Using the hostnamectl command

The hostnamectl command is a utility in Linux used to query and change the system’s hostname and related settings. It is part of the systemd suite of tools, which is widely used on modern Linux distributions. While its primary purpose is to manage the system’s hostname, hostnamectl can also provide valuable system information, such as the operating system version, kernel version, architecture, and more.

Key Information provided by hostnamectl are-

  • Static hostname: The system’s hostname (name of the machine).
  • Icon name: A symbolic name representing the system.
  • Chassis: The hardware type (e.g., VM for a virtual machine, desktop, etc.).
  • Machine ID: A unique identifier for the machine.
  • Boot ID: The unique identifier of the current boot session.
  • Operating System: The name and version of the OS installed.
  • Kernel: The Linux kernel version running on the system.
  • Architecture: The system’s architecture (e.g., x86-64, ARM).

To view only the os-version using hostnamectl command use-

$> hostnamectl | grep "Operating System"
os-version using hostnamectl command

Method-4: Using the uname command

The uname (short for “Unix name”) command is used to display system information. It provides details about the kernel, system architecture, and other important information. While uname does not provide the complete OS version (like lsb_release or hostnamectl), it can be useful for gathering kernel and system architecture details.

Options used with the uname command are-

-r : Displays the kernel version.

$> uname -r

-a : Displays all available system information, including the kernel version, architecture, and system name.

$> uname -a

-m : Displays the system architecture.

$> uname -m

-s : Displays the kernel name.

$> uname -s

Method-5: Using GUI

This method may vary across different Linux distributions, as each distro has its own GUI and settings layout. Here, we will demonstrate the process for Ubuntu Linux.

Step 1: Open the Settings application
  • Click on the Applications Menu button (bottom-left corner) or press the Super key (Windows key).
  • Type “Settings” and select the Settings application from the search results.
Step 2: Access the About section
  • In the Settings window, scroll down the left-hand menu.
  • Click on the About option at the bottom of the list.
Step 3: View the OS version

In the About section, you will see information about your system, including:

  • OS Name: The name of the distribution (e.g., Ubuntu).
  • OS Version: The version of Ubuntu installed (e.g., Ubuntu 20.04 LTS).
  • Codename: The codename of the release (e.g., Focal Fossa).
  • Other System Information: You can also see details about your computer’s hardware (processor, RAM, etc.).