We may earn a referral fee at no additional cost to you when you shop through the links on this page.
You are logged into a server over SSH and need to know exactly which Ubuntu release it runs before installing software or following a version-specific guide. This DevAnswers guide covers every reliable command-line way to check it, starting with the one source that is always present, then lsb_release, a couple of quick fallbacks, and the 32- vs 64-bit check.
The Reliable Way: /etc/os-release
The exact release decides which packages and security updates you get, whether your version is still supported, and which repository and PPA names apply, so “Ubuntu” on its own is rarely specific enough. The most reliable place to read it is /etc/os-release: the modern, systemd-originated standard for operating-system identification, present on every current Ubuntu and Debian system with no package required. Just read the file:
cat /etc/os-release
PRETTY_NAME="Ubuntu 26.04 LTS"
NAME="Ubuntu"
VERSION_ID="26.04"
VERSION="26.04 LTS (Resolute Raccoon)"
VERSION_CODENAME=resolute
ID=ubuntu
The output above is from an Ubuntu 26.04 system used to test these commands; your own values (version, codename) will reflect whatever release you are on.
Each field has a job: PRETTY_NAME is the full human label, VERSION_ID is just the number (best for scripts and comparisons), and VERSION_CODENAME is the adjective release name (noble, jammy) that apt repositories key off. To pull just the version number, grep for the field you want:
grep VERSION_ID /etc/os-release
VERSION_ID="26.04"
Because the file is shell-compatible, you can also source it and use the variables directly, handy inside a script that needs to branch on the release:
. /etc/os-release && echo "Running $NAME $VERSION_ID"
Running Ubuntu 26.04
VERSION_ID from /etc/os-release is the most reliable field to test against: it is always present, contains just the number, and needs no extra package. Two things the output tells you at a glance: whether this is an LTS release (it appears in PRETTY_NAME and VERSION), and the codename (resolute for 26.04, noble for 24.04), which is the name apt sources and PPAs are pinned to.
Because it is just a file, you can also read it on a remote box without an interactive shell, handy when checking a fleet of servers:
ssh user@your-server 'cat /etc/os-release'
PRETTY_NAME="Ubuntu 26.04 LTS"
VERSION_ID="26.04"
The same identification fields come straight back, with no shell to log out of.
lsb_release -a (and When It’s Missing)
The lsb_release command gives the same information in a clean, human-readable form:
lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 26.04 LTS
Release: 26.04
Codename: resolute
The -a form above prints everything; to narrow it down, -d gives just the description line, -r the release number, and -c the codename. The name comes from the Linux Standard Base, which is where the “LSB” in the command originates. One catch: lsb_release is part of the lsb-release package and is not always installed, minimal server, cloud, and Docker images often omit it. If you get command not found, either install it or fall back to /etc/os-release above:
sudo apt install lsb-release
hostnamectl
On any system running systemd (all standard Ubuntu installs), hostnamectl reports the OS alongside the hostname and kernel:
hostnamectl
Operating System: Ubuntu 26.04 LTS
Kernel: Linux 7.0.0-22-generic
Architecture: x86-64
It is a systemd tool, so it reads the same identification data the system uses everywhere else. Minimal containers without systemd will not have hostnamectl, though, another reason /etc/os-release is the safest default.
Quick Files: /etc/issue and /etc/lsb-release
Two more files hold the version in plain text. /etc/issue is the pre-login banner, and on Ubuntu /etc/lsb-release is present even on minimal images where the lsb_release command is not. (Debian does not ship /etc/lsb-release by default, so on Debian rely on /etc/os-release or /etc/debian_version instead.)
cat /etc/issue
cat /etc/lsb-release
Ubuntu 26.04 LTS \n \l
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=26.04
DISTRIB_CODENAME=resolute
DISTRIB_DESCRIPTION="Ubuntu 26.04 LTS"
32-bit or 64-bit?
To check the architecture, uname -m reports the kernel and dpkg --print-architecture reports the installed package architecture:
uname -m
dpkg --print-architecture
x86_64
amd64
x86_64 (from uname) and amd64 (from dpkg) both mean a 64-bit system; i686/i386 would mean 32-bit. This matters whenever you download a .deb directly or a vendor offers separate builds, you need the one that matches your architecture, and modern Ubuntu releases are 64-bit only.
One more environment worth a note: under WSL (Windows Subsystem for Linux), the file-based checks (/etc/os-release, /etc/issue) behave the same, run them inside your WSL Ubuntu session and they report the Ubuntu version, not the Windows host; hostnamectl only works there when systemd is enabled.
Summary
For scripts and for guaranteed availability, prefer /etc/os-release, it is always there and easy to parse. For a quick human-readable check, lsb_release -a or hostnamectl are fine when they are installed. Once you know your release, you are set to update Ubuntu safely or check which packages are installed before following a version-specific setup guide.
Comments