How to Check Your Ubuntu Version
Find which Ubuntu release you're on, get the codename for a repository line, and tell an LTS from an interim release. Tested on 26.04, 24.04 and 22.04.
Half the instructions on the internet only apply to one Ubuntu release, so the first thing to settle is which one you’re on. It’s the reason every guide here says which versions it was tested against, Apache included.
There are two commands worth knowing. One works everywhere, including inside a container that’s been stripped to the bone, and the other is the one you’ll see quoted most often.
Before You Start
- A terminal on the Ubuntu machine you’re asking about
None of this needs sudo, and none of it changes anything.
Step 1: Read the Release File
cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.4 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
PRETTY_NAME is the human answer, and it’s the line to quote when somebody asks. The LTS on the end of it is the part people miss: releases carrying it get five years of updates, and the ones without carry nine months.
VERSION gives you the point release as well. 24.04.4 is 24.04 with four years of fixes rolled in, and it matters when a bug report asks.
This file is part of systemd rather than Ubuntu, so it’s there on a minimal container image and on every other mainstream distribution too.
Step 2: The Same Answer From lsb_release
lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 24.04.4 LTS
Release: 24.04
Codename: noble
This is the one most guides reach for. It’s a small Python program rather than a file, and on a trimmed-down image it may not be installed, which is the one reason to prefer step 1 when you’re writing something that has to work anywhere. sudo apt install lsb-release puts it back.
Step 3: Just the Codename
. /etc/os-release && echo "$ID $VERSION_ID $VERSION_CODENAME"
ubuntu 24.04 noble
Sourcing the file makes every field a shell variable, which is how you get one clean value instead of a screenful. The codename is what third-party repositories want, so this is the form you paste into a deb line rather than typing noble from memory and finding out later you were a release out.
Verify It Worked
Two independent sources agreeing is a stronger answer than either on its own:
[ "$(lsb_release -rs)" = "$(. /etc/os-release; echo $VERSION_ID)" ] && echo "both agree on the version"
both agree on the version
If that prints nothing, the two disagree, which usually means the machine was upgraded in place and something didn’t finish. sudo apt update && sudo apt full-upgrade is where to start.
Conclusion
You’ve got the release number, the codename, and a way to check both without trusting either on its own. If the answer was older than you hoped, the codename from step 3 is the value you’ll need for whichever upgrade path you take next.
This is usually step zero on a machine somebody has just handed you. Renaming it is often step one.
If your machine reports something odd here, do send it to [email protected] along with the release you’re on, and I’ll take a look.