Linux System Version Command: How to Check Your OS Version in the Command Line

Linux System Version Command

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

If you are using the Linux operating system, starting up a new machine, or just looking for more information on your server’s OS, you can check the system Linux version using these methods with different Linux system version commands. 

Why Check Your Linux OS Version?

It is crucial to check your Linux OS version for the following scenarios: 

  • Keeping an eye on your OS version ensures that your applications and softwares are compatible with it. 
  • You can easily verify that your system receives appropriate critical patches and security updates. 
  • it can help diagnose issues based on OS specific configurations. 
  • It ensures that hardware and drivers function correctly. 
  • Knowing your assists in upgrades and mitigations by guiding smooth OS upgrades without breaking compatibility. 
  • Meets security and regulatory standards. 

Regularly checking your Linux OS using Linux system version commands helps keep the system efficient. 

Linux System Version Command Overview    

When working with Linux, it’s essential to know your OS version for compatibility, troubleshooting, or software installation. There are quite a few commands that you can use to check the OS version. Even though all of them serve the same purpose, they do display different results and information. Let’s walk through all of them to understand the results. 

Commands to Check Linux Operating System Version

Using lsb_release Command

The lsb_release command provides detailed information about distribution. It works on most Linux distributions, but if it’s missing on yours, you may need to install the lsb-core package.

Command: 

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

lsb_release -a

Output Example:

release -a

Using /etc/os-release File

This file contains OS-related details and is available on most modern distributions.

Command:

cat /etc/os-release

Output Example:

os release

Using cat /etc/*release Command

Some distributions use different release files, therefore, running this command will ensure that you get the detailed version of the distribution. 

Command: 

cat /etc/*release

Using hostnamectl Command

The hostnamectl command is used for managing hostnames but also provides OS version details.

Enhance Your CyerPanel Experience Today!
Discover a world of enhanced features and show your support for our ongoing development with CyberPanel add-ons. Elevate your experience today!

Command:

hostnamectl

Output Example:

hostnamectl

Using uname Command

While uname is mainly used for kernel-related information, it can provide basic OS details.

Command:

uname -a

Output Example:

uname -a

To get the kernel version only, use:

Command: 

uname -r

Using dmesg | grep Linux

The dmesg command displays system messages, including kernel-related details.

Command:

dmesg | grep Linux

Output Example:

grep linux

Checking Linux Kernel Version vs. OS Version

Many times, users confuse the Linux kernel version with the OS version, but they are quite different. 

  • OS Version: Refers to the specific Linux distribution and release (e.g., Ubuntu 22.04, CentOS 7, Debian 11).
  • Kernel Version: Refers to the core of the Linux system that interacts with hardware (e.g., Linux 5.15.0-84-generic).

Checking the OS Version

Use one of these commands:

lsb_release -a  # Works on Ubuntu, Debian, and derivatives

cat /etc/os-release  # Works on most modern Linux distributions

Example Output:

lsb release

Checking the Kernel Version

Use the uname command:

uname -r

Example Output:

uname -r

For detailed kernel info, use:

uname -a

Key Differences Between OS Version & Kernel Version

FeatureOS Version (Distribution)Kernel Version
DefinitionThe specific Linux distribution and releaseThe core Linux system managing hardware and processes
ExampleUbuntu 22.04, CentOS 7, Debian 11Linux 5.15.0-84-generic
Update MethodUpdated via package manager (apt, yum)Updated separately, often via apt update or manual compilation
ImpactAffects software compatibility and system featuresAffects hardware support, performance, and security

OS Version Commands for Different Linux Distributions

Different Linux distributions store OS version details in different locations. Below are the commands to check. 

Ubuntu and Debian-based Distros

These distributions include Ubuntu, Debian, Linux Mint, and Pop!_OS.

Commands:

lsb_release -a

cat /etc/os-release

cat /etc/lsb-release  # Older versions

Example Output (Ubuntu 22.04):

ubuntu os release

CentOS, RHEL, and Fedora

These distributions include CentOS, Red Hat Enterprise Linux (RHEL), Fedora, and Rocky Linux.

Commands:

cat /etc/redhat-release

cat /etc/os-release

openSUSE and SUSE Linux Enterprise (SLES)

These include openSUSE Leap, openSUSE Tumbleweed, and SUSE Linux Enterprise Server (SLES).

Commands:

cat /etc/os-release

cat /etc/SuSE-release  # Older versions 

Arch Linux

Arch-based distributions include Arch Linux, Manjaro, and EndeavourOS.

Commands:

cat /etc/os-release

How to Find the Version of Installed Packages

Checking the version of installed packages is essential for troubleshooting, compatibility, and ensuring that you have the latest security updates. 

Debian & Ubuntu (APT-based systems)

  • Check the version of a specific package:

dpkg -l | grep <package-name>

Example for checking the curl package:

dpkg -l | grep curl

Example output:

grep curl
  • Alternative command using apt

apt list –installed | grep <package-name>

Example:

apt list –installed | grep nginx

Example output:

grep nginx

RHEL, CentOS, Fedora (YUM/DNF-based systems)

  • Check the version of a specific package:

rpm -q <package-name>

Example:

rpm -q httpd

  • Alternative command using dnf (for newer systems):

dnf list installed | grep <package-name>

Example:

dnf list installed | grep mysql

  • For older systems using yum:

yum list installed | grep <package-name>

Arch Linux & Manjaro (Pacman-based systems)

  • Check the version of a specific package:

pacman -Qi <package-name>

Example:

pacman -Qi firefox

  • List all installed packages and versions:

pacman -Q

openSUSE & SLES (Zypper-based systems)

  • Check the version of a specific package:

zypper info <package-name>

Example:

zypper info openssh

  • List all installed packages and versions:

zypper se –installed-only

Universal Methods (Work on Most Linux Systems)

  • Using which to locate the binary of a package:

which nginx

Example output:

which nginx
  • Using –version or -v flag (for many CLI tools)

Most command-line tools allow checking their version directly:

nginx -v

python –version

git –version

Automating OS Version Checks with Scripts

Below are Bash scripts that work across different Linux distributions.

1. Universal OS Version Check Script

How to Use the Script:

  • Save the script as check_os_version.sh.
  • Run the script:

2. Scheduled OS Version Check (Using Cron Jobs)

To automate this script at regular intervals, use a cron job:

Open the cron job editor:
crontab -e

Add a line to check the OS version every Monday at 10 AM and save it to a log file:
0 10 * * 1 /path/to/check_os_version.sh >> /var/log/os_version.log 2>&1

3. OS Version Check with Logging

To store OS version details in a log file for tracking:

Conclusion

Checking your Linux OS version is crucial for software compatibility, security updates, and troubleshooting. Use commands like lsb_release -a, cat /etc/os-release, or hostnamectl depending on your distribution. Automating these checks with scripts and cron jobs ensures regular monitoring and system security.

Marium Fahim
Hi! I am Marium, and I am a full-time content marketer fueled by an iced coffee. I mainly write about tech, and I absolutely love doing opinion-based pieces. Hit me up at [email protected].
Unlock Benefits

Become a Community Member

SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!