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:
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:
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:
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.
![](https://cyberpanel.net/wp-content/uploads/2024/01/developer-laptop.webp)
Command:
hostnamectl
Output Example:
Using uname Command
While uname is mainly used for kernel-related information, it can provide basic OS details.
Command:
uname -a
Output Example:
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:
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:
Checking the Kernel Version
Use the uname command:
uname -r
Example Output:
For detailed kernel info, use:
uname -a
Key Differences Between OS Version & Kernel Version
Feature | OS Version (Distribution) | Kernel Version |
Definition | The specific Linux distribution and release | The core Linux system managing hardware and processes |
Example | Ubuntu 22.04, CentOS 7, Debian 11 | Linux 5.15.0-84-generic |
Update Method | Updated via package manager (apt, yum) | Updated separately, often via apt update or manual compilation |
Impact | Affects software compatibility and system features | Affects 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):
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:
- Alternative command using apt
apt list –installed | grep <package-name>
Example:
apt list –installed | grep nginx
Example output:
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:
- 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
This script detects the Linux distribution and displays the OS version:
echo “Checking Linux OS Version…”
if [ -f /etc/os-release ]; then
. /etc/os-release
echo “OS: $PRETTY_NAME”
echo “Version ID: $VERSION_ID”
echo “Codename: $VERSION_CODENAME”
elif command -v lsb_release &>/dev/null; then
echo “OS: $(lsb_release -ds)”
echo “Version: $(lsb_release -rs)”
echo “Codename: $(lsb_release -cs)”
elif [ -f /etc/redhat-release ]; then
echo “OS: $(cat /etc/redhat-release)”
elif command -v hostnamectl &>/dev/null; then
echo “OS: $(hostnamectl | grep ‘Operating System’ | cut -d ‘:’ -f2)”
else
echo “OS version information not found.”
fi
How to Use the Script:
- Save the script as check_os_version.sh.
Give execution permission:
chmod +x check_os_version.sh
- Run the script:
./check_os_version.sh
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:
LOG_FILE=”/var/log/os_version_check.log”
echo “=== OS Version Check on $(date) ===” >> $LOG_FILE
if [ -f /etc/os-release ]; then
. /etc/os-release
echo “OS: $PRETTY_NAME” >> $LOG_FILE
echo “Version ID: $VERSION_ID” >> $LOG_FILE
elif command -v lsb_release &>/dev/null; then
echo “OS: $(lsb_release -ds)” >> $LOG_FILE
elif [ -f /etc/redhat-release ]; then
echo “OS: $(cat /etc/redhat-release)” >> $LOG_FILE
else
echo “OS version information not found.” >> $LOG_FILE
fi
echo “—————————–” >> $LOG_FILE
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.