System administrators frequently need to verify the exact OS version to ensure compatibility with software repositories and security patches. Knowing how to check os version in linux is a fundamental skill that saves time and prevents configuration errors. Whether you are troubleshooting a server or setting up a new workstation, identifying the distribution and release number is the first step. This guide covers multiple command-line methods, from simple one-liners to detailed system file checks.
Linux distributions vary widely, but the core tools remain consistent. You will learn commands that work on Ubuntu, Debian, CentOS, Fedora, and many others. Each method provides slightly different information, so you can choose what fits your task best. Let’s start with the quickest approach.
Using The Hostnamectl Command
The hostnamectl command is part of systemd and works on most modern Linux systems. It shows the operating system name, version, and kernel details in a clean format. This is often the fastest way to get a complete picture.
Open your terminal and type:
hostnamectl
The output will include lines like “Operating System: Ubuntu 22.04.3 LTS” and “Kernel: Linux 5.15.0-91-generic”. You don’t need any extra flags. If your system uses systemd, this command is your best friend.
One small note: Some older distributions or minimal installations might not have systemd. In that case, the command will return an error. But for the vast majority of modern Linux setups, it works perfectly.
Checking With The Lsb-Release Command
The lsb_release command is specifically designed to show Linux Standard Base information. It is common on Debian-based systems like Ubuntu and Linux Mint. However, it may not be installed by default on some distributions.
First, check if it is available:
lsb_release -a
If you see output like “Distributor ID: Ubuntu” and “Release: 22.04”, you are good. If the command is not found, you can install it using your package manager. For Debian/Ubuntu:
sudo apt install lsb-release
For Fedora or CentOS, the package is called redhat-lsb-core. But honestly, you might not need it if other methods work. The -d flag shows only the description line, which is often enough:
lsb_release -d
This gives a clean, single line output like “Description: Ubuntu 22.04.3 LTS”.
Reading The Os-Release File
Every modern Linux distribution includes a file at /etc/os-release. This file contains standardized variables that describe the operating system. It is part of the systemd project, but even non-systemd systems often have it.
To view its contents, use:
cat /etc/os-release
You will see lines like:
- NAME=”Ubuntu”
- VERSION=”22.04.3 LTS (Jammy Jellyfish)”
- ID=ubuntu
- ID_LIKE=debian
- VERSION_ID=”22.04″
- PRETTY_NAME=”Ubuntu 22.04.3 LTS”
The PRETTY_NAME variable is usually the most human-readable. You can extract it directly with:
grep PRETTY_NAME /etc/os-release
This method works on almost all distributions, including Arch Linux, Fedora, and openSUSE. It is reliable and does not require any extra packages.
How To Check Os Version In Linux Using The Issue File
Another classic file is /etc/issue. It contains a short text string that is displayed before the login prompt. Many distributions update this file with the OS version.
Run:
cat /etc/issue
Typical output might be “Ubuntu 22.04.3 LTS \n \l”. The \n and \l are placeholders for the newline and terminal line, so the actual version is clear. However, some systems do not keep this file updated, so it is less reliable than /etc/os-release.
There is also /etc/issue.net, which is used for network logins. It usually contains the same information. But stick with the local file for accuracy.
Using The Uname Command For Kernel Version
Sometimes you need the kernel version rather than the distribution release. The uname command is the standard tool for this. It shows the kernel name, version, and architecture.
To see the full kernel version:
uname -a
This prints something like “Linux hostname 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux”. If you want only the kernel release number:
uname -r
The output “5.15.0-91-generic” tells you the exact kernel build. This is useful when checking for security patches or hardware support. Note that the kernel version does not directly tell you the distribution version, but it helps in context.
Checking Version On Red Hat And CentOS
Red Hat Enterprise Linux and CentOS have their own specific files. The /etc/redhat-release file contains the distribution name and version. On newer CentOS Stream versions, the file might be /etc/centos-release.
View it with:
cat /etc/redhat-release
Output example: “CentOS Stream release 9”. For older CentOS 7, it would be “CentOS Linux release 7.9.2009 (Core)”. Fedora also uses this file, but it is symlinked to /etc/fedora-release.
On some systems, you might also find /etc/system-release which is a generic symlink. These files are plain text and easy to parse in scripts.
Using The Dmesg Command
The dmesg command shows kernel ring buffer messages, which include boot information. It is not the most direct method, but it can reveal the OS version if other files are missing.
Try:
dmesg | grep -i "linux version"
This will show a line like “Linux version 5.15.0-91-generic (buildd@lcy02-amd64-062) (gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023”. The distribution name is often mentioned in the build path.
This method works even on systems without systemd or standard release files. However, it requires root privileges on some systems to read the full dmesg log.
How To Check Os Version In Linux With Graphical Tools
If you are using a desktop environment, you can often find the OS version in the system settings. On GNOME, go to Settings > About. On KDE, look in System Settings > About This System. These graphical tools read the same underlying files we discussed.
For server environments, the command line is faster and more reliable. But if you are on a desktop, the GUI can be a quick visual check. Just remember that the terminal methods give you more detailed control.
One common graphical tool is neofetch or screenfetch. These display a colorful logo along with OS, kernel, and hardware info. They are not installed by default, but you can install them easily:
sudo apt install neofetch
Then run neofetch to see a nice summary.
Scripting And Automation Tips
When you need to check the OS version in a script, use the /etc/os-release file. It is standardized and easy to parse with grep or awk. For example, to get just the version ID:
source /etc/os-release && echo $VERSION_ID
This works in bash scripts without external commands. Alternatively, you can use:
awk -F= '/^VERSION_ID/{print $2}' /etc/os-release | tr -d '"'
For kernel version in scripts, uname -r is the simplest. Combine both to create a full system identifier. Remember that different distributions might have slight variations, but these commands cover 99% of cases.
Common Pitfalls And Troubleshooting
Sometimes the lsb_release command is not installed, and you get a “command not found” error. Do not panic. Just use cat /etc/os-release instead. Another issue is that some containers or minimal images might not include release files. In that case, check /proc/version:
cat /proc/version
This shows the kernel version and compiler info, but not the distribution name. For containers, you might need to rely on environment variables set by the host.
If you are using an immutable distribution like Fedora Silverblue or openSUSE MicroOS, the standard files still exist. However, the version shown might refer to the base image rather than the running system. Always verify with multiple methods.
Comparing Output Across Distributions
Different Linux families have unique identifiers. Debian-based systems (Ubuntu, Mint) use /etc/debian_version as well. Red Hat-based systems (CentOS, Fedora) use /etc/redhat-release. Arch Linux uses /etc/arch-release which is often empty, but the version is in /etc/os-release.
Here is a quick reference:
- Ubuntu:
/etc/os-releaseorlsb_release -a - CentOS:
/etc/redhat-releaseorhostnamectl - Fedora:
/etc/fedora-releaseor/etc/os-release - Debian:
/etc/debian_versionorlsb_release -a - openSUSE:
/etc/os-releaseorcat /etc/SuSE-release(older)
Memorizing these can save you time when working with unfamiliar systems.
Using The Getconf Command
The getconf command is primarily for system configuration variables, but it can show the GNU libc version, which sometimes correlates with the OS version. Run:
getconf GNU_LIBC_VERSION
This outputs something like “glibc 2.35”. While not a direct OS version, it gives a clue about the system’s age. Newer glibc versions are found on newer distributions. This is a niche method, but it works when nothing else is available.
How To Check Os Version In Linux Remotely
When managing remote servers via SSH, you can use the same commands. Just log in and run hostnamectl or cat /etc/os-release. For automated monitoring, tools like Ansible or Puppet can collect this information. But for a quick manual check, SSH is all you need.
One tip: If you have many servers, create a simple script that loops through a list of hosts and runs ssh user@host "cat /etc/os-release". This gives you a quick inventory of OS versions across your infrastructure.
Understanding The Output Fields
When you read /etc/os-release, you will see several variables. Here is what they mean:
NAME: The distribution name (e.g., “Ubuntu”)VERSION: Full version string (e.g., “22.04.3 LTS (Jammy Jellyfish)”)ID: Short identifier (e.g., “ubuntu”)VERSION_ID: Numeric version (e.g., “22.04”)PRETTY_NAME: Human-friendly display stringID_LIKE: Parent distribution (e.g., “debian”)
Knowing these fields helps you parse the file in scripts. For example, if you need to check if the system is Debian-based, look for ID_LIKE=debian.
Frequently Asked Questions
Q: What is the easiest command to check OS version in Linux?
A: The easiest is hostnamectl if your system uses systemd. Otherwise, cat /etc/os-release works on almost all distributions.
Q: How do I check the Linux kernel version?
A: Use uname -r to get the kernel release number. For full details, use uname -a.
Q: Why does lsb_release not work on my system?
A: The lsb_release command is not installed by default on some distributions like Fedora or Arch. Install the lsb-release package or use /etc/os-release instead.
Q: Can I check the OS version without using the terminal?
A: Yes, on desktop environments, go to Settings > About. You can also install neofetch for a graphical terminal display.
Q: How do I check the OS version on a remote server?
A: SSH into the server and run any of the commands mentioned, such as hostnamectl or cat /etc/os-release.
Final Thoughts On Checking OS Version
Mastering these commands makes you more efficient as a system administrator. You no longer have to guess which distribution a server runs. The methods described here cover all major Linux families and edge cases. Remember to verify with at least two different commands to ensure accuracy, especially on custom or minimal installations.
Practice these commands on your own system. Try them on different distributions if you have access. Over time, you will memorize the most useful ones. The key is to know that /etc/os-release is your universal fallback. It is rare to find a Linux system without it.
Now you have a complete toolkit for identifying any Linux OS version. Use it wisely and keep your systems compatible and secure.