How To Get Os Version In Linux – Checking With Lsb Release Command

Checking your Linux operating system version can be done with a single command in the terminal, but knowing how to get OS version in Linux is essential for troubleshooting, software compatibility, and system administration. Whether you are a beginner or a seasoned user, this guide will walk you through every reliable method with clear steps and examples.

Linux distributions vary widely, from Ubuntu and Fedora to Debian and Arch. Each has its own way of storing version information. The good news is that you don’t need to memorize dozens of commands. A few core tools will cover almost every scenario.

In this article, you will learn multiple commands, understand the files that hold version data, and discover how to interpret the output. We will also cover GUI methods and scripting for automation. Let’s get started.

Why Knowing Your OS Version Matters

Understanding your Linux version helps you install the right packages, apply security patches, and avoid compatibility issues. For example, a package built for Ubuntu 22.04 may not work on Ubuntu 20.04. Similarly, kernel updates often depend on your distribution version.

System administrators use version information to maintain consistency across servers. Developers need it to target their software correctly. Even casual users benefit when troubleshooting forum posts or asking for help online.

Knowing the version also tells you when your system reaches end-of-life. This is critical for security. You can plan upgrades before support ends.

How To Get Os Version In Linux

This section covers the most common and reliable commands. Each method works on most distributions, but some are distribution-specific. We will start with the universal approach.

Using The lsb_release Command

The lsb_release command is part of the Linux Standard Base (LSB) package. It displays distribution-specific information. It is available on Ubuntu, Debian, and many others.

  1. Open a terminal.
  2. Type: lsb_release -a
  3. Press Enter.

You will see output like:

Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:        22.04
Codename:       jammy

If the command is not found, install it with your package manager. For Debian-based systems: sudo apt install lsb-release. For Red Hat-based: sudo yum install redhat-lsb-core.

You can also use lsb_release -d to show only the description line. This is useful for scripts.

Checking The /etc/os-release File

Almost all modern Linux distributions include a file called /etc/os-release. This file contains standardized variables. It is part of the systemd project.

To view it, run:

cat /etc/os-release

Example output:

PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian

You can also source this file in a shell script to use the variables. For example, source /etc/os-release; echo $VERSION_ID.

Some older distributions may use /etc/lsb-release instead. Check that file if /etc/os-release is missing.

Using The hostnamectl Command

If your system uses systemd, the hostnamectl command provides system information including the OS version. It is simple and fast.

Run:

hostnamectl

Output example:

   Static hostname: my-pc
         Icon name: computer-vm
           Chassis: vm
        Machine ID: abc123...
           Boot ID: def456...
    Virtualization: kvm
  Operating System: Ubuntu 22.04.3 LTS
            Kernel: Linux 5.15.0-91-generic
      Architecture: x86-64

The “Operating System” line gives you the distribution and version. This command works on Fedora, CentOS, Debian, and most systemd-based distros.

Checking Kernel Version With uname

Sometimes you need the kernel version rather than the distribution version. The uname command is the standard tool for this.

Common usage:

  • uname -r – shows the kernel release (e.g., 5.15.0-91-generic)
  • uname -a – shows all system information
  • uname -v – shows kernel version number

Kernel version is important for hardware support and driver compatibility. For example, newer kernels support newer graphics cards.

Distribution-Specific Commands

Different families have their own tools. Here are the most common ones:

Debian And Ubuntu

Use lsb_release -a as described. Alternatively, check /etc/debian_version:

cat /etc/debian_version

This shows the Debian version number, even on Ubuntu. For Ubuntu, you can also use cat /etc/ubuntu-release.

Red Hat, CentOS, And Fedora

Red Hat-based systems use /etc/redhat-release:

cat /etc/redhat-release

Example: CentOS Linux release 7.9.2009 (Core)

For Fedora, the same file works. You can also use rpm -q centos-release or rpm -q fedora-release.

Arch Linux

Arch uses a rolling release model, so there is no version number per se. But you can check /etc/arch-release (often empty) or use pacman -Q filesystem to see the filesystem package version.

For the kernel version, uname -r works fine.

OpenSUSE

OpenSUSE uses /etc/SuSE-release or cat /etc/os-release. The command zypper --version also shows the package manager version.

Using Graphical User Interface (GUI)

If you prefer a graphical method, most desktop environments show system information in the settings.

  • GNOME: Go to Settings > About. You will see the OS name and version.
  • KDE Plasma: Open System Settings > About This System.
  • XFCE: Look in the menu under System > About.

These methods are slower than the terminal but useful for new users.

Scripting And Automation

For system administrators, scripting version checks is common. Here is a simple bash script to extract the OS version:

#!/bin/bash
if [ -f /etc/os-release ]; then
    . /etc/os-release
    echo "OS: $NAME $VERSION"
elif [ -f /etc/lsb-release ]; then
    . /etc/lsb-release
    echo "OS: $DISTRIB_ID $DISTRIB_RELEASE"
else
    echo "Cannot determine OS version."
fi

You can also parse the output of lsb_release with grep and awk. For example:

lsb_release -d | awk -F"\t" '{print $2}'

This prints only the description line.

Common Pitfalls And Troubleshooting

Sometimes commands return unexpected results. Here are a few issues and fixes:

  • Command not found: Install the required package (e.g., lsb-release).
  • Empty output: The file might be missing. Check /etc/*release for alternatives.
  • Wrong version: Some containers or chroot environments may show the host’s version. Use uname for the kernel.
  • Permission denied: Most files are readable by all users. If not, use sudo.

Comparing Output Across Distributions

Here is a quick reference table for common distros:

Distribution Best Command Key File
Ubuntu lsb_release -a /etc/os-release
Debian cat /etc/debian_version /etc/os-release
Fedora cat /etc/fedora-release /etc/os-release
CentOS cat /etc/centos-release /etc/redhat-release
Arch uname -r /etc/arch-release
openSUSE cat /etc/SuSE-release /etc/os-release

Remember that some files may be symlinks. For example, /etc/redhat-release often points to /etc/centos-release on CentOS.

Understanding Version Numbers

Linux version numbers can be confusing. Here is what they mean:

  • Major.Minor.Patch: e.g., Ubuntu 22.04.3 – major 22, minor 04, patch 3.
  • LTS: Long Term Support, typically 5 years of updates.
  • Codename: A development name like “Jammy Jellyfish”.
  • Kernel version: e.g., 5.15.0 – major 5, minor 15, patch 0.

Knowing the difference helps when reading documentation or asking for help.

Checking Version Without Terminal

If you cannot use the terminal, try these:

  • Look at the boot screen (GRUB menu) – sometimes shows the kernel version.
  • Check the system log: cat /var/log/syslog | grep "Linux version" (needs terminal).
  • Use a live USB – the version is often displayed during boot.

But honestly, the terminal is the easiest way.

Why Multiple Methods Exist

Linux is modular. Different components track version information differently. The kernel has its own version, the distribution has another, and packages have their own. Each method gives you a piece of the puzzle.

For example, uname -r gives the kernel version, while lsb_release -d gives the distribution version. Both are useful depending on your task.

Best Practices For System Administrators

If you manage multiple servers, automate version checks. Use configuration management tools like Ansible or Puppet. For example, an Ansible playbook can gather facts including OS version.

Also, keep a central inventory. Document each server’s OS version, kernel, and installed packages. This helps with upgrade planning and security audits.

Regularly check for end-of-life announcements. For example, Ubuntu 20.04 reaches end of standard support in April 2025. Plan upgrades ahead of time.

Frequently Asked Questions

1. What is the simplest command to check my Linux version?
The simplest is lsb_release -a if available. Otherwise, cat /etc/os-release works on most systems.

2. How do I find the kernel version in Linux?
Use uname -r. This works on all Linux distributions.

3. Why does lsb_release not work on my system?
The package may not be installed. Install it with your package manager, or use /etc/os-release instead.

4. Can I get the OS version from a script?
Yes. Source /etc/os-release and use the variables, or parse the output of lsb_release with tools like grep and awk.

5. What is the difference between distribution version and kernel version?
The distribution version refers to the OS release (e.g., Ubuntu 22.04). The kernel version is the core of the OS (e.g., 5.15.0). Both are important for different reasons.

Conclusion

Now you know multiple ways to check your Linux OS version. Start with lsb_release -a or cat /etc/os-release. For kernel info, use uname -r. Each method has its place, and you can choose based on your distribution and needs.

Remember that knowing your version helps with software installtion, troubleshooting, and security. Make it a habit to check before installing new packages or asking for help online.

If you encounter any issues, refer back to this guide. The commands are simple, and the files are standard. With practice, you will be able to identify any Linux system in seconds.

Thank you for reading. If you found this helpful, share it with others who are learning Linux. Happy command lining!