How To Find Ubuntu Version

How To Find Ubuntu Version

Reading time1 min
#Linux#Ubuntu#Sysadmin#UbuntuVersion#LinuxCommands#SystemInfo

Mastering System Transparency: Accurately Identifying Your Ubuntu Version

Patch management, OS-level troubleshooting, and package compatibility checks all begin with a single hard fact: the exact version of Ubuntu you’re running. Mistakes here lead to broken dependencies, missed vulnerabilities, or botched upgrades.


The Go-To: /etc/os-release

When you need authoritative OS identification, /etc/os-release is the true source of record for modern Ubuntu systems (since 16.04).

cat /etc/os-release

Typical output:

NAME="Ubuntu"
VERSION="22.04.4 LTS (Jammy Jellyfish)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 22.04.4 LTS"
VERSION_ID="22.04"

Pin down the VERSION_ID for scripting, or use PRETTY_NAME for reporting.

Note:
Some cloud images may have subtle differences here—double-check format if parsing.


lsb_release – Clean Output, Script-Ready

lsb_release standardizes distribution info across Debian-based systems. The -a flag provides complete details.

lsb_release -a

Output:

Distributor ID: Ubuntu
Description:    Ubuntu 22.04.4 LTS
Release:        22.04
Codename:       jammy

For automation, limit output with:

lsb_release -rs    # Yields: 22.04

Edge case:
If you get -bash: lsb_release: command not found, quickly restore functionality via:

sudo apt update && sudo apt install lsb-release

Not all minimal containers include this binary by default.


Systemd Host Info: hostnamectl

Introduced with systemd (Ubuntu 16.04+), hostnamectl is often overlooked. It combines hostname, kernel, and OS data—useful for asset inventory scripts.

hostnamectl

Excerpt:

Operating System: Ubuntu 22.04.4 LTS
Kernel: Linux 5.15.0-86-generic
Architecture: x86-64

Quick, but the OS line is less detailed than /etc/os-release.


Legacy & Fallback: /etc/issue and /etc/lsb-release

Both files are often referenced by legacy scripts, but beware:

cat /etc/issue        # Sometimes static, missing point releases
cat /etc/lsb-release  # Not always present; content and format can vary

Sample /etc/issue may look like:

Ubuntu 22.04.4 LTS \n \l

Minimum utility; avoid for automation in multiversion environments.


One-Liner: Extract Only the Version Number

For CI/CD pipelines, you typically want a plain version string. Try:

grep VERSION_ID /etc/os-release | cut -d '"' -f2
# Or, with lsb_release:
lsb_release -rs

Returned:

22.04

No codename, no extra text—ideal for scripts like:

if [ "$(lsb_release -rs)" = "22.04" ]; then
  # Run Ubuntu 22.04-specific tasks
fi

Non-obvious tip:
/etc/os-release is present even in most containers, where lsb_release might be missing.


Quick Reference

CommandOutput scopeNotes
cat /etc/os-releaseFull OS detailsMost reliable, machine-parseable
lsb_release -aHuman/script friendlyRequires optional package
lsb_release -rsRaw version idScripting favorite
hostnamectlHost + OS + kernelFor systemd-based systems
cat /etc/issueStatic bannerMay be out-of-date, incomplete
cat /etc/lsb-releaseBasic distro infoSometimes missing or inconsistent

Gotcha: Partial Upgrades and Inconsistent Files

Partial-release upgrades, especially interrupted dist-upgrades, can leave stale data in /etc/issue or /etc/lsb-release. Always cross-check with /etc/os-release for definitive results.


Final Note

Identifying your Ubuntu version isn’t just busywork—it’s foundational for debugging, patching, and maintaining system hygiene. Use /etc/os-release or lsb_release for accuracy. Avoid relying on /etc/issue unless running throwaway test VMs.

Do this right, and downstream failure modes (like deploying packages built for the wrong glibc or kernel ABI) become far less likely.

No magic. Just facts—grab the version, and move on to what actually matters.