Back to blog
Guides·10 min read

Check Ubuntu Version on a Server: 5 Reliable Commands

Check Ubuntu Version on a Server: 5 Reliable Commands

The fastest way to check Ubuntu version on a server is cat /etc/os-release. This single file holds information about the release number, codename, and pretty name in a machine-and-human-readable format.

This guide is aimed at system administrators, developers, and everyone else who SSH'ed into a brand new VPS or bare-metal server and needs to identify the Ubuntu LTS release prior to installing packages, pinning dependencies, or planning an upgrade. You will learn how to check Ubuntu version using five practical methods, which to trust, which to take only kernel version from, and which command to use in automation to check Ubuntu version.

Quick answer: check Ubuntu version with two commands

If you are in urgent need to check Ubuntu version, use cat /etc/os-release and lsb_release -a. The former prints the release file directly, while the latter prints the summary many admins already know.

bash

cat /etc/os-release

bash

lsb_release -a

A typical release file holds the distribution name, full version string, release number, and codename. For cases when you need just the number, use lsb_release -sr, which will print just the number, like 24.04.

bash

lsb_release -sr

Use quick checks if you are in a rush. Use script-safe checks listed further when the command becomes a part of a deployment, audit, or installation procedure.

Why it matters to check Ubuntu version before you do anything

Names of packages, repository paths, language version defaults, kernel version, and upgrade paths all depend on the Ubuntu release. A command that is safe to use on one LTS may pull the wrong dependency on another LTS.

It matters for support as well. The naming of Ubuntu releases depends on the date, thus release number tells the release month and year. LTS releases arrive in April of even-numbered years, with interims in between. Prior to checking whether a server can run any agent, panel, trading bot, or a monitoring stack, check the Ubuntu version first to see whether the vendor supports it.

On OrbitServers installations, we recommend to do this check right after your first login, prior to installation of an application stack. It takes several seconds and prevents a category of errors you get after configuration files are changed.

Method 1: Check Ubuntu version with lsb_release

The traditional Ubuntu version command is lsb_release -a. It prints distributor ID, description, release number, and codename in short summary.

bash

lsb_release -a

Sample output:

bash

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04.3 LTS
Release:        24.04
Codename:       noble

Flags which may come in handy are lsb_release -sr (prints only the release number), lsb_release -sc (prints only the codename), and lsb_release -sd (prints only the description).

bash

lsb_release -sr   # release number only
lsb_release -sc   # codename only
lsb_release -sd   # description only

On minimal cloud images, the command may be absent. If you are getting 'command not found' error, read the release file directly or install the tiny package with sudo apt update && sudo apt install -y lsb-release. Do not install the package if you got what you needed from the release file.

Method 2: Read the release file for a script-safe answer

This is the method to use in automation: cat /etc/os-release. The file is available in modern systemd-based Ubuntu distributions and holds a key-value set.

bash

cat /etc/os-release

Typical output:

bash

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

For scripts, do not parse the pretty string. Source the file and read the variables, as illustrated below. This way, you get distribution ID, numeric version, and codename without guessing about spaces and wording.

bash

source /etc/os-release
echo "$NAME $VERSION_ID ($VERSION_CODENAME)"

Output:

bash

Ubuntu 24.04 (noble)

For script, if you need only the numeric version, use:

bash

source /etc/os-release
printf '%s\n' "$VERSION_ID"

For one-liners that do not source the file, use:

bash

awk -F= '/^VERSION_ID=/{gsub(/"/,"",$2); print $2}' /etc/os-release

This is the best approach to use for Ansible facts, bootstrap scripts, inventory checks, and preflight validation before installation of the software. It is also the best approach if you need the same answer across a fleet and cannot rely on a package that is not always present.

Method 3: Use hostnamectl to get OS and kernel in one view

hostnamectl command is good when you need to know OS and the kernel in one shot. The output typically includes hostname, virtualization type, operating system line, kernel line, and architecture.

bash

hostnamectl

Sample output:

bash

 Static hostname: app-node-01
       Icon name: computer-vm
         Chassis: vm
  Virtualization: kvm
Operating System: Ubuntu 24.04.3 LTS
          Kernel: Linux 6.8.0-71-generic
    Architecture: x86-64

Parse the operating system line to check Ubuntu version. Parse the kernel line if the question is about the kernel, not distribution version.

Method 4: neofetch to quickly visually inspect Ubuntu version

If the server holds neofetch command, you can quickly read its output for distro logo, OS, kernel, uptime, packages, shell, and hardware. Useful when taking screenshot, handing-over the server or visually inspecting it.

bash

neofetch

It is not a good tool for automation. The output was designed for manual reading, its exact format may vary due to the configuration, terminal width, and additional packages installed. On a minimal server, do not install this command just to check Ubuntu version. Read the release file and proceed.

Method 5: uname cannot check Ubuntu version

The uname -r command is frequently misused. It prints the version of running kernel, not Ubuntu release. A server can run an Ubuntu release with an older or newer kernel depending on image, hardware enablement stack, or pinning.

bash

uname -r

It returns something like:

bash

6.8.0-71-generic

If you need more kernel details, use uname -a or cat /proc/version. These commands are good for driver troubleshooting, kvm, eBPF, networking features, and vendor kernel requirements. Do not use these commands to check whether your app supports one Ubuntu LTS over another.

bash

uname -a
cat /proc/version

If the server is Amazon Linux, not Ubuntu

Sometimes the actual answer is that it is not Ubuntu at all. Amazon Linux has a release file too, yet its values are different. The distribution ID points to Amazon Linux, and version ID follows the Amazon-specific release scheme instead of Ubuntu's date-based numbering.

bash

cat /etc/os-release

Amazon Linux 2023 output looks closer to this:

bash

NAME="Amazon Linux"
VERSION="2023"
ID="amzn"
ID_LIKE="fedora"
PRETTY_NAME="Amazon Linux 2023"
VERSION_ID="2023"

You may also find a separate file with the release line, specific to Amazon Linux.

bash

cat /etc/system-release

The practical difference here is that Ubuntu uses apt, while newer Amazon Linux uses dnf, and older Amazon Linux systems often use yum. If the distribution ID is not Ubuntu, stop using Ubuntu-specific instructions and follow the vendor's Amazon Linux documentation or internal image standard.

A fast preflight checklist for scripts

Prior to continuing with installation or deployment of any application, check three things: the distribution ID, the numeric version, and the codename. The code snippet below demonstrates the idea: source the release file, print values, and quit if the machine is not Ubuntu or its release is not in your testing list.

bash

source /etc/os-release

echo "ID=$ID"
echo "VERSION_ID=$VERSION_ID"
echo "VERSION_CODENAME=$VERSION_CODENAME"

Then gate the job:

bash

source /etc/os-release

if [[ "$ID" != "ubuntu" ]]; then
  echo "This installer expects Ubuntu." >&2
  exit 1
fi

case "$VERSION_ID" in
  22.04|24.04)
    echo "Supported Ubuntu LTS: $VERSION_ID"
    ;;
  *)
    echo "Untested Ubuntu release: $VERSION_ID" >&2
    exit 1
    ;;
esac

Have a limited allowlist. If you have only tested two LTS releases, state it. A failure during package installation costs more time than graceful exit from the script.

LTS or interim: what the version number tells you

The first thing to decode is the date built into the release number. The LTS release number corresponds to April of an even-numbered year. Interim releases are used to fill the gap between LTS releases.

When it comes to production servers, the question is not whether the server runs the latest release. The question is whether it is supported by all applications that are run. A newer interim release can be ok for lab server, yet wrong for a payments worker, a latency-sensitive bot, or a database node. Prior to making a decision whether the release is supported by your application, check the application support, kernel requirements, and your own upgrade window.

If the server is already live, do not start a release upgrade just because there is a newer release. Take the snapshot or backup, confirm the restore works, and test the upgrade path in staging environment prior to moving to production. In case the performance is affected by location, use the latency checker prior to moving workload closer to the exchange, broker, or endpoint.

Common mistakes when you check Ubuntu version

Mistake one is to believe the name of shell prompt or hostname. This is a naming convention, not evidence.

Mistake two is using the kernel version as the distro version. This is a useful number, just answers a different question.

Mistake three is parsing the pretty release string in automation. Use the numeric version and codename fields in the release file instead.

Mistake four is assuming that a minimal image has the release tool. It often does not hold true.

Mistake five is checking the version once and not writing it down somewhere. Store release, codename, kernel, and install date in runbook or inventory. You will thank yourself during an incident.

Frequently Asked Questions

What is the quickest command to check Ubuntu version?

Use cat /etc/os-release. It works on modern Ubuntu server images and gives the version, codename, and pretty name in one file. If you only need the number, run lsb_release -sr.

How do I check Ubuntu version command line on a minimal image?

Use the release file. Minimal images often omit the classic release summary tool, yet have the release file. Install the tool with sudo apt update && sudo apt install -y lsb-release if you need to use it explicitly.

How do I find Ubuntu version in a shell script?

Source the release file and read the numeric version variable. For codename, read the codename variable. Avoid parsing human-readable strings in automation.

Is the kernel version the same as the Ubuntu version?

No. The kernel command shows the running kernel. The Ubuntu version comes from the release file or the classic release summary command. A supported Ubuntu release can run different kernels depending on the image and update policy.

Do I need sudo to check Ubuntu version?

Usually no. Checking the release file, running the release summary command, getting host details, and getting kernel version all work for regular users. You need sudo to install the release package on a minimal image.

Conclusion

To check Ubuntu version on a server, use cat /etc/os-release. Use lsb_release -a if you want the summary, hostnamectl if you want OS and kernel in one shot, neofetch if you need a human-readable output, and uname -r only if you need the kernel version.

If you are building a new server for your latency-sensitive applications, bots, or production workloads, check the Ubuntu version prior to installing dependencies. Start with a clean VPS, move to bare metal if you need dedicated hardware, and contact sales if you need help picking the right location for your workloads.

Ready to deploy? View Plans or Contact Sales.

Get started with Orbit Servers

Low-latency VPS, bare metal, and colocation across the US, EU, and APAC - provisioned instantly and built for performance-critical workloads.

Get started
J

Written by

Julius

Related posts