How to Check Linux OS Version and Distribution (Ubuntu, RHEL, AlmaLinux, Debian)

check linux version - custom-osver-featured.png

Before installing a package, following a tutorial or opening a support ticket, you need to know exactly which Linux distribution and version the server runs,
and sometimes which kernel and CPU architecture. There is one command that works almost everywhere, plus a few others for older or minimal systems.

Quick answer: cat /etc/os-release shows the distribution and version on every modern Linux; uname -r shows the kernel version; hostnamectl shows both.

Check /etc/os-release (Works Everywhere)

/etc/os-release is a standard file on every systemd-era distribution: Ubuntu, Debian, RHEL, AlmaLinux, Rocky, Fedora, SUSE and more. PRETTY_NAME is the human-readable version; ID and VERSION_ID are handy in scripts.

bashos-release
cat /etc/os-release
grep PRETTY_NAME /etc/os-release
textexample on AlmaLinux 9
NAME="AlmaLinux"
VERSION="9.6 (Sage Margay)"
ID="almalinux"
VERSION_ID="9.6"
PRETTY_NAME="AlmaLinux 9.6 (Sage Margay)"
/etc/os-release
The universal answer

Use hostnamectl for OS, Kernel and Hardware

On systemd systems, hostnamectl prints the operating system, kernel, architecture and whether the machine is a VM, all in one go.

bashhostnamectl
hostnamectl
#  Operating System: Ubuntu 24.04.3 LTS
#            Kernel: Linux 6.8.0-87-generic
#      Architecture: x86-64
#    Virtualization: kvm
TipThe same command changes the hostname; see change hostname with hostnamectl.
hostnamectl
OS, kernel, architecture, virtualization

Use lsb_release on Ubuntu and Debian

lsb_release prints distribution information in a fixed format. It is installed by default on Ubuntu; on minimal Debian or RHEL-family systems you may need to install it.

bashlsb_release
lsb_release -a
lsb_release -ds        # description only
sudo apt install lsb-release      # if missing (Debian)
sudo dnf install redhat-lsb-core  # if available (older RHEL)
lsb_release
Ubuntu and Debian friendly

Distribution Release Files

Older systems without os-release keep their version in a distribution-specific file. These also help when a minimal container image strips other tools.

bashrelease files
cat /etc/redhat-release     # RHEL, CentOS, AlmaLinux, Rocky
cat /etc/debian_version     # Debian (Ubuntu shows the Debian base)
cat /etc/issue
ls /etc/*release*
Release files
redhat-release, debian_version

Check the Kernel Version With uname

The distribution version and the kernel version are different things. uname -r shows the running kernel, which is what drivers, modules and many vulnerability notices refer to.

bashkernel
uname -r
uname -a
cat /proc/version
NoteMore detail on uname options is in the uname guide.
Kernel version
uname -r and uname -a

Check 32-bit or 64-bit and CPU Architecture

Download pages often ask for x86_64 (amd64) or aarch64 (arm64). uname -m answers that; dpkg --print-architecture or rpm --eval '%{{_arch}}' show the package architecture.

basharchitecture
uname -m                  # x86_64 or aarch64
getconf LONG_BIT          # 64
dpkg --print-architecture # Debian/Ubuntu: amd64
lscpu | head -5
Architecture
x86_64, aarch64

Inside Containers and Remote Servers

A container reports its image’s distribution but the host’s kernel, so os-release and uname -r can disagree. For many servers, run the check over SSH in a loop.

bashcheck several servers
for h in web1 web2 db1; do
  echo -n "$h: "; ssh "$h" 'grep PRETTY_NAME /etc/os-release | cut -d\" -f2'
done
bashinside a Docker container
docker exec -it app cat /etc/os-release
Containers and remote hosts
Image OS vs host kernel

Use the Version in Scripts

Source /etc/os-release to get shell variables, then branch on $ID so one script works on both Debian-family and RHEL-family systems.

bashdetect the package manager
. /etc/os-release
case "$ID" in
  ubuntu|debian) sudo apt update ;;
  rhel|almalinux|rocky|centos|fedora) sudo dnf makecache ;;
  *) echo "Unsupported: $PRETTY_NAME"; exit 1 ;;
esac
Scripting with os-release
Branch on $ID

Quick Reference

How do I check my Linux version?

Run cat /etc/os-release. The PRETTY_NAME line shows the distribution and version, for example Ubuntu 24.04 LTS or AlmaLinux 9.6.

How do I check the Ubuntu version from the command line?

Use lsb_release -a or cat /etc/os-release. Both show the release number and codename.

How do I check the kernel version in Linux?

Run uname -r. It shows the version of the kernel currently running.

How do I check if Linux is 32-bit or 64-bit?

Run uname -m. x86_64 or aarch64 means 64-bit; i686 or i386 means 32-bit.

How do I check the RHEL or AlmaLinux version?

Run cat /etc/redhat-release or cat /etc/os-release.

Cheat Sheet

  • cat /etc/os-release, hostnamectl, lsb_release -a
  • uname -r kernel, uname -m architecture, cat /etc/redhat-release

Related tutorials

Diagrams are original illustrations by Gnome IT Solutions. Tutorial text © Gnome IT Solutions.