The command line offers several fast methods to identify your Linux operating system version without navigating through graphical menus. If you are new to Linux or just need a quick answer, learning how to check os version in linux command line is a fundamental skill. This guide covers all the reliable commands, from simple one-liners to detailed system information, ensuring you always know exactly what you are working with.
Knowing your OS version helps with troubleshooting, installing compatible software, and understanding security updates. Whether you use Ubuntu, Fedora, Debian, or CentOS, the terminal provides consistent ways to get this data. Let’s jump straight into the most effective methods.
How To Check Os Version In Linux Command Line
This section covers the primary commands you can run in any terminal. Each method works on most distributions, but some are more universal than others. We’ll start with the simplest and most reliable approach.
Using The Hostnamectl Command
The hostnamectl command is part of systemd, which almost all modern Linux distributions use. It displays the operating system name, version, kernel version, and architecture. This is often the fastest way to get a clear output.
- Open your terminal emulator (Ctrl+Alt+T on most systems).
- Type the following command and press Enter:
hostnamectl
You will see output similar to this:
Static hostname: my-pc
Icon name: computer-laptop
Chassis: laptop
Machine ID: abc123def456
Boot ID: ghi789jkl012
Operating System: Ubuntu 22.04 LTS
Kernel: Linux 5.15.0-91-generic
Architecture: x86-64
The line “Operating System” gives you the exact version. For example, “Ubuntu 22.04 LTS” or “Fedora 38”. This command works on any systemd-based distro, including Debian, Red Hat, and Arch Linux.
Checking The Os-Release File
Another universal method is reading the /etc/os-release file. This file is present on almost every Linux distribution and contains standardized variables. You can view it with the cat command.
- Run this command:
cat /etc/os-release
Output example:
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"
UBUNTU_CODENAME=jammy
The PRETTY_NAME variable gives you a human-readable version. This method is reliable even on older systems that lack systemd.
Using The Lsb_Release Command
The lsb_release utility is part of the Linux Standard Base (LSB). It is not always installed by default, but it is common on Debian-based distributions like Ubuntu. If it is missing, you can install it with your package manager.
- Check if it is available:
lsb_release -a
If installed, output looks like:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy
If you get a “command not found” error, install it with:
sudo apt install lsb-release # Debian/Ubuntu
sudo yum install redhat-lsb-core # RHEL/CentOS
Once installed, the -r flag shows only the release number, and -c shows the codename.
Checking The Kernel Version
Sometimes you need the kernel version rather than the distribution version. The kernel is the core of the OS. Use the uname command for this.
- Full kernel version:
uname -r - All system info:
uname -a
Example output for uname -r:
5.15.0-91-generic
This tells you the kernel release. The -a flag adds the hostname, kernel name, and architecture. This command works on every Linux system, regardless of distribution.
Reading The Issue File
Older distributions or minimal installations may not have /etc/os-release. In that case, check /etc/issue or /etc/issue.net. These files contain a simple identification string.
- Run:
cat /etc/issue
Output example:
Ubuntu 22.04 LTS \n \l
The \n and \l are placeholders for the hostname and terminal line. This method is not as detailed but works in a pinch.
Using The Dmesg Command
The kernel ring buffer, accessed via dmesg, also contains version information. This is useful if you are troubleshooting boot issues.
- Run:
dmesg | grep -i "linux version"
Output:
[ 0.000000] Linux version 5.15.0-91-generic (buildd@lgw01-amd64-038) (gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #1-Ubuntu SMP Tue Jan 10 15:24:45 UTC 2023
This shows the kernel version and the compiler used to build it. It is more technical but can be helpful for advanced users.
Checking The Distribution With Package Managers
Some package managers store version information. For example, on Debian-based systems, you can check the /etc/debian_version file.
- Run:
cat /etc/debian_version
Output:
11.7
This tells you the Debian version number (e.g., 11.7 for Debian 11). On Red Hat-based systems, check /etc/redhat-release.
cat /etc/redhat-release
Output:
CentOS Linux release 7.9.2009 (Core)
These distribution-specific files are reliable but only work on their respective families.
Using The Neofetch Tool
If you want a visually appealing output with system details, install neofetch. It displays the OS logo, version, kernel, uptime, and hardware info.
- Install it:
sudo apt install neofetch # Debian/Ubuntu
sudo dnf install neofetch # Fedora
- Run:
neofetch
Output includes a colorful ASCII logo and lines like:
OS: Ubuntu 22.04 LTS x86_64
Kernel: 5.15.0-91-generic
This is not installed by default but is a popular tool for sharing system info in forums.
Automating Version Checks In Scripts
If you need to check the OS version programmatically, use the /etc/os-release file with grep or awk. For example, to get only the version ID:
grep ^VERSION_ID /etc/os-release | cut -d '=' -f2
Output:
"22.04"
Or remove quotes with tr:
grep ^VERSION_ID /etc/os-release | cut -d '=' -f2 | tr -d '"'
This is useful for automation scripts that need to adapt behavior based on the OS version.
Common Issues And Troubleshooting
Sometimes commands return unexpected results. Here are a few scenarios:
- Command not found: If
lsb_releaseorneofetchis missing, install the appropriate package. - Empty output: Some minimal Docker containers lack
/etc/os-release. Trycat /etc/*releaseto see all available files. - Different formatting: Older distributions may use
/etc/centos-releaseor/etc/SuSE-release. Check withls /etc/*release*.
If you are on a live USB or a rescue environment, the version shown may be the live system, not the installed OS. Always check the root filesystem if you have mounted it.
Why Version Matters
Knowing your OS version helps with:
- Security patches: End-of-life versions no longer receive updates.
- Software compatibility: Some applications require specific kernel or library versions.
- Support forums: When asking for help, include your version to get accurate advice.
For example, Ubuntu 20.04 and 22.04 have different package versions. A command that works on 22.04 might fail on 18.04 due to missing dependencies.
Comparing Methods: Which One To Use?
Here is a quick comparison table:
| Command | Reliability | Detail Level | Distribution |
|---|---|---|---|
| hostnamectl | High | Medium | All systemd |
| cat /etc/os-release | Very High | High | All modern |
| lsb_release -a | Medium | Medium | Debian-based |
| uname -a | Very High | Low (kernel only) | All |
| neofetch | Low (not installed) | Very High | All |
For most users, hostnamectl or cat /etc/os-release is the best choice. They are simple and work on nearly every system.
Step-By-Step Example For Beginners
If you are completly new to the terminal, follow these steps:
- Open the terminal. Look for it in your app menu or press Ctrl+Alt+T.
- Type
hostnamectland press Enter. - Look for the line that says “Operating System”. That is your version.
- If that does not work, type
cat /etc/os-releaseand look forPRETTY_NAME.
Thats all you need. You now know your Linux version.
Advanced: Parsing Version For Scripts
If you are writing a shell script that needs to act differently on different versions, use conditional logic. For example:
#!/bin/bash
VERSION=$(grep ^VERSION_ID /etc/os-release | cut -d '=' -f2 | tr -d '"')
if [ "$VERSION" = "22.04" ]; then
echo "Running Ubuntu 22.04"
else
echo "Other version: $VERSION"
fi
This extracts the version number and compares it. You can extend this to check for specific distributions using ID from /etc/os-release.
Checking Version On Embedded Or Minimal Systems
On systems like Alpine Linux (common in Docker containers), the commands above may not work. Alpine uses /etc/alpine-release.
- Run:
cat /etc/alpine-release
Output:
3.18.4
For BusyBox-based systems, try cat /proc/version which shows kernel info.
Summary Of Commands
Here is a quick reference list:
hostnamectl– OS and kernel infocat /etc/os-release– Distribution detailslsb_release -a– LSB info (install if needed)uname -r– Kernel versioncat /etc/issue– Simple identificationneofetch– Pretty output (install first)cat /etc/debian_version– Debian-specificcat /etc/redhat-release– Red Hat-specific
Memorize two or three of these, and you will never be stuck wondering what OS you are using.
Frequently Asked Questions
What is the easiest way to check Linux version?
The easiest way is to run hostnamectl. It requires no installation and works on most modern distributions. If that fails, use cat /etc/os-release.
How do I check the OS version without using the terminal?
While this article focuses on the command line, you can also check via graphical settings. On Ubuntu, go to Settings > About. On Fedora, look in Settings > Details. But the terminal is faster for remote or headless systems.
Why does lsb_release -a show “No LSB modules are available”?
This is normal. It means the LSB modules are not installed, but the command still shows distribution info. You can ignore the warning.
Can I check the OS version on a remote server?
Yes, if you have SSH access. Connect to the server and run any of the commands above. For example: ssh user@server 'cat /etc/os-release'.
What if I am using a container like Docker?
Inside a Docker container, run cat /etc/os-release or uname -a. Some minimal containers may only have /etc/alpine-release or /proc/version.
Final Thoughts
Mastering how to check os version in linux command line is a small but powerful skill. It saves time when troubleshooting and ensures you use the right commands for your system. Whether you prefer hostnamectl for its simplicity or /etc/os-release for its detail, you now have multiple tools at your disposal.
Practice these commands on your own machine. Try them on different distributions if you have access. Over time, they will become second nature. Remember, the terminal is your friend—it gives you direct access to the heart of the system.
If you encounter any errors, double-check the command spelling. Linux commands are case-sensitive. Also, ensure you have the necessary permissions; most of these commands work without sudo, but reading some system files might require root access on locked-down systems.
Now go ahead and check your Linux version. You have all the knowledge you need.