Ubuntu Version Checking: Ubuntu vs Debian for Checking Linux Distribution Versions

Use cat /etc/os-release first when checking Ubuntu or Debian versions. It is the most consistent command across modern systems, scripts well, and does not depend on optional tools. Ubuntu is based on Debian, but the two distributions expose version details slightly differently, especially on minimal servers and containers. For example, Ubuntu 24.04 LTS is a long-term support release supported by Canonical for standard security maintenance through 2029 [source: Ubuntu].

TLDR: For Ubuntu and Debian, run cat /etc/os-release first, then use lsb_release -a if it exists. On Ubuntu, lsb_release is often available and gives clean output such as Description: Ubuntu 22.04.5 LTS. On Debian, expect /etc/os-release to be more reliable, while /etc/debian_version can add useful point-release detail. In a 50-server audit, using /etc/os-release can cut manual checking time by half because one command works across both families.

Why version checking matters

Version checking sounds simple. It often is. Then a production script fails because one server is Ubuntu, another is Debian, and a third is a tiny container image with half the usual tools missing. That is the annoying part.

Linux distribution version data affects patching, package repositories, compliance checks, Docker base image selection, monitoring labels, and support tickets. A wrong version string can send an engineer toward the wrong package name or repository path. Expect to waste time on that if you trust only one command without checking the file behind it.

Ubuntu and Debian are closely related. Ubuntu uses Debian packaging tools such as dpkg and apt. Still, their release names, support policies, and default metadata files are not always identical.

The best first command: /etc/os-release

The file /etc/os-release is the safest starting point on both Ubuntu and Debian.

cat /etc/os-release

Typical Ubuntu output includes:

NAME="Ubuntu"
VERSION="24.04.1 LTS (Noble Numbat)"
ID=ubuntu
ID_LIKE=debian
VERSION_ID="24.04"
VERSION_CODENAME=noble

Typical Debian output includes:

PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian

Why this works well:

  • It is plain text. Scripts can parse it without special packages.
  • It shows the distribution ID. Use ID=ubuntu or ID=debian.
  • It gives the version number. Use VERSION_ID for automation.
  • It includes the codename. Ubuntu uses names like noble. Debian uses names like bookworm.

For automation, prefer this pattern:

. /etc/os-release
echo "$ID $VERSION_ID $VERSION_CODENAME"

This works in shell scripts because /etc/os-release uses variable-style entries. Be careful with custom images, though. Some vendors modify fields or add branding.

Ubuntu version checking

On Ubuntu, the common checks are simple:

lsb_release -a
cat /etc/os-release
hostnamectl
cat /etc/issue

lsb_release -a is popular because it reads cleanly:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.5 LTS
Release:        22.04
Codename:       jammy

That output is good for humans. It is less ideal for scripts because the tool may be missing from slim images. Honestly, it feels like the one command everyone remembers is also the one most likely to be absent from a stripped container.

hostnamectl can also show the operating system:

hostnamectl

It may return a line such as:

Operating System: Ubuntu 24.04.1 LTS

This is useful on full servers running systemd. It is not a safe choice inside many containers. If systemd is not present, the command may fail or show limited data.

Ubuntu also keeps older compatibility files, such as /etc/lsb-release:

cat /etc/lsb-release

You may see:

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=24.04
DISTRIB_CODENAME=noble
DISTRIB_DESCRIPTION="Ubuntu 24.04.1 LTS"

This file is useful, but do not rely on it as your only source. /etc/os-release is the better default.

Debian version checking

On Debian, start with:

cat /etc/os-release

Then check Debian’s own version file:

cat /etc/debian_version

It may return something like:

12.7

That is helpful when you need the point release. Debian 12, named bookworm, was released in June 2023 [source: Debian]. The codename matters because Debian repositories and documentation often refer to codenames rather than only version numbers.

Be careful with /etc/debian_version on derivatives. Ubuntu may also contain Debian-related files because it is Debian-based. Seeing a Debian file does not automatically mean the system is Debian. Trust ID from /etc/os-release first.

Ubuntu vs Debian: key differences

Check Ubuntu Debian
/etc/os-release Best default choice Best default choice
lsb_release -a Common on full installs May need package installation
/etc/debian_version Not proof of Debian Useful for point release
hostnamectl Good on systemd hosts Good on systemd hosts
uname -a Kernel, not distro Kernel, not distro

The biggest mistake is using uname to identify the distribution.

uname -a

This shows kernel information. It does not tell you whether the userland is Ubuntu or Debian. It can say “Linux” and include a kernel version, but that is not enough for package decisions.

Practical command order

For a serious check, use this order:

  1. Run cat /etc/os-release.
  2. Confirm ID, VERSION_ID, and VERSION_CODENAME.
  3. On Ubuntu, optionally run lsb_release -a.
  4. On Debian, optionally run cat /etc/debian_version.
  5. Use hostnamectl only as a secondary check on full hosts.
  6. Do not use uname as distro proof.

For a short script, use:

if [ -r /etc/os-release ]; then
  . /etc/os-release
  printf '%s %s %s\n' "$ID" "$VERSION_ID" "$VERSION_CODENAME"
else
  echo "Cannot identify distribution"
fi

This returns a compact result such as:

ubuntu 24.04 noble

or:

debian 12 bookworm

What about containers and cloud images?

Containers make version checking messier. A Docker image may not include lsb_release, hostnamectl, or even common admin utilities. Minimal Ubuntu and Debian images are built to stay small. That means fewer commands.

In containers, /etc/os-release is usually still present. That is why it remains the best first check. If it is missing, the image is either very small, very old, or custom-built in a way that will cause other maintenance headaches too.

Cloud images add another layer. AWS, Azure, and private image builders may add vendor packages or custom kernels. Still, the distribution identity should come from the operating system metadata, not from the kernel string.

Common errors to avoid

  • Do not confuse kernel version with distribution version. uname is not enough.
  • Do not assume Ubuntu just because apt exists. Debian uses it too.
  • Do not assume Debian just because /etc/debian_version exists. Derivatives may keep it.
  • Do not install packages just to identify a system. Read existing files first.
  • Do not parse pretty descriptions when stable fields exist. Use ID and VERSION_ID.

Recommended standard for teams

Teams should standardize on /etc/os-release for inventory, scripts, monitoring, and support intake. Ask for three fields: ID, VERSION_ID, and VERSION_CODENAME. That gives enough detail for most package, patching, and troubleshooting tasks.

If the system is Ubuntu, lsb_release -a is fine for a human-readable support note. If it is Debian, add /etc/debian_version when the point release matters. Keep hostnamectl as a secondary check. Keep uname for kernel questions only.

The short rule is simple: use /etc/os-release to identify the distribution, use Debian or Ubuntu-specific files only to add detail, and never let kernel output decide your package path.