Use lsb_release -a on Ubuntu when you need clean distribution details, and use hostnamectl on Red Hat systems when you want OS, kernel, architecture, virtualization, and hostname data in one shot. If either command is missing or oddly configured, check /etc/os-release. That file is the reliable fallback across most modern Linux distributions.
TLDR: On Ubuntu, run lsb_release -a to see the release number, codename, and description, such as Ubuntu 22.04.4 LTS jammy. On Red Hat, run hostnamectl to get a wider system summary, including Operating System: Red Hat Enterprise Linux and the kernel version. In a 50-server patch audit, using the right command first can save around 15 to 20 minutes of repeated checks. If both commands annoy you by not existing, run cat /etc/os-release.
Contents
Why checking the Linux version matters
Linux version checks sound basic until something breaks. A package fails. A kernel module refuses to load. A vendor asks for the exact release. Suddenly, “it’s Ubuntu” or “it’s Red Hat” is not enough.
You usually need four facts:
- Distribution name, such as Ubuntu, Debian, Red Hat Enterprise Linux, AlmaLinux, or Rocky Linux.
- Version number, such as Ubuntu 20.04 or RHEL 9.3.
- Codename or release label, such as jammy or bookworm.
- Kernel version, such as
5.14.0-362.el9.x86_64.
The catch is that Linux gives you several ways to ask the same question. Some commands are neat. Some are missing. Some return too much. Some return just enough to make you suspicious.
Ubuntu: using lsb_release
On Ubuntu, the classic command is:
lsb_release -a
A typical result looks like this:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.4 LTS
Release: 22.04
Codename: jammy
This is compact and readable. It gives you the exact Ubuntu version and codename without making you scan ten extra lines. That is why admins often prefer it during support calls or upgrade planning.
If you only want the description, use:
lsb_release -d
For only the release number:
lsb_release -r
For only the codename:
lsb_release -c
That last one matters more than many new users expect. Ubuntu repositories and upgrade paths often refer to codenames. For example, Ubuntu 22.04 is jammy, while Ubuntu 24.04 is noble.
Honestly, it feels like lsb_release should always be installed on Ubuntu, but minimal cloud images sometimes leave it out. If you see command not found, install it with:
sudo apt update
sudo apt install lsb-release
Or skip the install and read the release file directly:
cat /etc/os-release
Red Hat: using hostnamectl
On Red Hat Enterprise Linux and its close relatives, hostnamectl is often the faster all-in-one check:
hostnamectl
You may see output like this:
Static hostname: rhel9-app01
Icon name: computer-vm
Chassis: vm
Machine ID: 8f3a...
Boot ID: 4c2b...
Virtualization: kvm
Operating System: Red Hat Enterprise Linux 9.3 (Plow)
CPE OS Name: cpe:/o:redhat:enterprise_linux:9::baseos
Kernel: Linux 5.14.0-362.el9.x86_64
Architecture: x86-64
Hardware Vendor: Red Hat
Hardware Model: KVM
This is more than a version check. It shows the hostname, virtualization type, operating system, kernel, and CPU architecture. That makes it useful when you are checking inventory, building audit reports, or confirming whether a server is physical or virtual.
For Red Hat systems, you can also use:
cat /etc/redhat-release
Example:
Red Hat Enterprise Linux release 9.3 (Plow)
This file is short and easy to read. It is also common on CentOS, Rocky Linux, AlmaLinux, and Oracle Linux, though the text will vary.
lsb_release vs hostnamectl: what is the real difference?
lsb_release focuses on distribution identity. It tells you what distribution you are running and which release it is. It is clean, simple, and great for Ubuntu.
hostnamectl comes from systemd. It reports host identity and operating system details. It works on many Linux systems, not only Red Hat. You can run it on Ubuntu too, and it will probably work. Still, Red Hat administrators often reach for it because it reveals more system context in one command.
| Task | Best command | Best fit |
|---|---|---|
| Check Ubuntu version and codename | lsb_release -a |
Ubuntu desktops and servers |
| Check Red Hat OS and kernel | hostnamectl |
RHEL, Rocky, AlmaLinux, CentOS Stream |
| Use a universal fallback | cat /etc/os-release |
Most modern Linux systems |
| Check only the kernel | uname -r |
Any Linux distribution |
The universal fallback: /etc/os-release
If you remember only one file, make it this one:
cat /etc/os-release
It usually returns data like:
NAME="Ubuntu"
VERSION="22.04.4 LTS (Jammy Jellyfish)"
ID=ubuntu
VERSION_ID="22.04"
VERSION_CODENAME=jammy
PRETTY_NAME="Ubuntu 22.04.4 LTS"
On Red Hat, it might show:
NAME="Red Hat Enterprise Linux"
VERSION="9.3 (Plow)"
ID="rhel"
VERSION_ID="9.3"
PRETTY_NAME="Red Hat Enterprise Linux 9.3 (Plow)"
This file is friendly to scripts. For example, automation tools can read ID and VERSION_ID without parsing messy human text. That helps when one script needs to support Ubuntu, Debian, RHEL, Rocky Linux, and AlmaLinux.
What about the kernel version?
The distribution version and kernel version are not the same thing. Ubuntu 22.04 may run different kernel versions depending on hardware enablement, cloud images, or updates. Red Hat systems may also keep older kernels installed after patching.
To check the running kernel, use:
uname -r
For a broader kernel and hardware summary, use:
uname -a
Expect to waste time if you confuse OS release with kernel release. A vendor might certify software for RHEL 8.8, but a driver issue may depend on the running kernel. You need both facts.
Quick workflow for admins
Use this short checklist when you log into a Linux server and need answers fast:
- Run
cat /etc/os-releaseto identify the distribution. - On Ubuntu, run
lsb_release -afor a clean release summary. - On Red Hat, run
hostnamectlfor OS, kernel, host, and virtualization data. - Run
uname -rto confirm the active kernel. - Save the output if you are preparing a support ticket or upgrade plan.
Best practical choice
For Ubuntu, lsb_release -a is the most readable version check. For Red Hat, hostnamectl gives the best single-screen system summary. For scripts, mixed fleets, and rescue sessions, /etc/os-release is the safest fallback.
That simple split prevents confusion. Ubuntu gives you clean release labels through lsb_release. Red Hat gives you richer host data through hostnamectl. Add uname -r for the kernel, and you have the information most support teams, auditors, and upgrade plans will ask for.