How To Check Os Version In Linux

4 min read

How to Check OS Version in Linux: A Complete Guide

Knowing the exact version of your Linux distribution is essential for troubleshooting, installing compatible software, and ensuring system security. Think about it: whether you are a system administrator managing servers, a developer testing applications, or a curious hobbyist exploring the command line, You've got several reliable ways worth knowing here. This guide walks you through the most common methods, explains what each command reveals, and shows you how to interpret the output so you can confidently identify your Linux environment Easy to understand, harder to ignore..


Why Checking the OS Version Matters

Linux is not a single monolithic operating system; it is a kernel combined with countless distributions (distros) such as Ubuntu, Debian, CentOS, Fedora, Arch, and many more. Each distro may ship with different package managers, default libraries, and release cycles. Knowing the precise version helps you:

  • Select the right repositories – Some PPAs or third‑party repos only support specific releases.
  • Apply security patches – Vulnerability advisories often reference a particular version number.
  • Ensure compatibility – Proprietary drivers (e.g., NVIDIA) or enterprise software may require a minimum kernel or glibc version.
  • Document environments – For reproducibility in CI/CD pipelines or when sharing bug reports.

With that in mind, let’s dive into the practical commands you can use right now.


Quick Overview of Common Commands

Command What It Shows Typical Output Example
lsb_release -a Linux Standard Base (LSB) details, including distributor ID, description, release, and codename Distributor ID: Ubuntu<br>Description: Ubuntu 22.04.3 LTS<br>Release: 22.04<br>Codename: jammy
cat /etc/os-release Distribution‑specific identification file (part of systemd) NAME="Ubuntu"<br>VERSION="22.Still, 04. On top of that, 3 LTS (Jammy Jellyfish)"<br>ID=ubuntu<br>VERSION_ID=22. 04
hostnamectl System hostname and operating system information (uses systemd) Operating System: Ubuntu 22.Day to day, 04. 3 LTS<br>Kernel: Linux 6.But 2. Even so, 0-36-generic
uname -r Kernel release version only 6. Consider this: 2. 0-36-generic
cat /etc/*release* Aggregates any release files present (useful on minimal or non‑systemd systems) Multiple lines showing distro info
rpm -q --whatprovides redhat-release (RHEL/CentOS) Package providing the release file redhat-release-8.Which means 6-0. 5.Practically speaking, el8. Which means x86_64
pacman -Qi base (Arch) Details about the base package, which includes the release info `Version : 2023. 09.

Some disagree here. Fair enough.

Below, each method is explained in depth, with step‑by‑step instructions and tips for interpreting the results Turns out it matters..


Method 1: Using lsb_release

The Linux Standard Base (lsb) initiative aimed to increase compatibility among Linux distributions. Most modern distros ship the lsb_release utility, which reads /etc/lsb-release or /etc/os-release and formats the data nicely.

How to Run It

lsb_release -a

What the Flags Mean

  • -a – Show all available information (ID, description, release, codename).
  • -d – Description only (e.g., “Ubuntu 22.04.3 LTS”).
  • -r – Release number only.
  • -c – Codename only.
  • -i – Distributor ID.

Example Output

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

If you see “No LSB modules are available,” it simply means the optional LSB packages aren’t installed; the core data is still displayed.

When to Use It

  • You need a quick, human‑readable summary.
  • You are writing scripts that parse the description or release fields.
  • You work across multiple distros and want a consistent interface.

Limitations

  • On very minimal installations (e.g., Docker containers, embedded systems) the lsb_release package may be missing. In that case, fall back to the next methods.

Method 2: Reading /etc/os-release

The file /etc/os-release is part of the systemd project and is present on virtually all modern Linux distributions, even those that do not use systemd as their init system (many still ship the file for compatibility). It contains key‑value pairs that are easy to parse programmatically Worth keeping that in mind..

How to View It

cat /etc/os-release

Typical Content

NAME="Ubuntu"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 22.04.3 LTS"
VERSION_ID=22.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=jammy
UBUNTU_CODENAME=jammy

Parsing Tips

  • NAME – Human‑readable distro name.
  • VERSION – Full version string, often includes the codename in parentheses.
  • VERSION_ID – Numeric version (useful for comparisons).
  • ID – Lowercase identifier (e.g., ubuntu, debian, centos, fedora, arch).
  • ID_LIKE – Indicates similarity to other distros (helpful for determining package manager).

When to Use It

  • You need machine‑parsable output (e.g., in Bash, Python, or Ansible).
  • You are in a container where lsb_release is not installed.
  • You want to avoid invoking external utilities and rely solely on filesystem data.

Limitations

  • Some very old or highly customized systems might lack this file. In such cases, check /etc/issue or distribution‑specific release files (see Method 4).

Method 3: Using hostnamectl

Part of systemd, the hostnamectl command primarily manages the system hostname but also prints operating system and kernel information. It works on any system that runs systemd (which includes most desktop and server distros released after ~2015).

How to Run It

hostnamectl

Sample Output

   Static hostname: my-laptop
         Icon name: computer-laptop
           Chassis: laptop
        Machine ID: 3f9a1b2c3d4e5f6g7h8i9j0k1l2m3n4o
           Boot ID: a1b2c3d4-e5f6-7890-abcd-ef1234567890
    Virtualization: kvm
  Operating System: Ubuntu 22.04.3 LTS
      Kernel: Linux
Hot New Reads

Hot Off the Blog

Explore the Theme

Other Perspectives

Thank you for reading about How To Check Os Version In Linux. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home