You log into a remote server, stare at the blinking cursor, and realize you are not entirely sure which distribution or version is running under the hood. Whether you are debugging a compatibility issue, installing a new package, or just performing a routine audit, knowing your system's exact identity is the first step.

In the Linux ecosystem, there isn't just one way to find this information, but there are definitely better ways. Instead of trying random commands until one works, use this guide to pinpoint your distribution and kernel version instantly.

If you need the information right now and don't care about the details, run this command. It works on almost every modern Linux distribution:

cat /etc/os-release

This will print your distribution name, version ID, and codename in a clean format.

1. Reading the /etc/os-release File (The Standard)

In the past, every distribution had its own unique text file for versioning. Fortunately, modern Linux systems (especially those using systemd) have standardized this. The cat /etc/os-release command is currently the most reliable method to get the full picture of your OS.

Open your terminal and type: cat /etc/os-release

You will see an output similar to this:

PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
ID=ubuntu

The PRETTY_NAME line is usually exactly what you are looking for. It combines the distro name and version into a human-readable string. Navigating through system configuration files like this can sometimes be confusing if you are new to the file system structure. If you ever find yourself lost or unable to locate a specific folder, our guide on how to find a directory on linux can help you master file navigation.

2. Using Hostnamectl

Originally designed to query and change the system hostname, the hostnamectl command has evolved into a fantastic tool for getting a system summary. It provides the kernel version and operating system info in a much cleaner output than reading raw files. hostnamectl

The output is concise and informative:

Static hostname: devcrea-server
       Icon name: computer-vm
         Chassis: vm
      Machine ID: ...
         Boot ID: ...
  Virtualization: kvm
Operating System: Ubuntu 22.04.3 LTS
          Kernel: Linux 5.15.0-91-generic
    Architecture: x86-64

Look at the Operating System and Kernel lines. This command is particularly useful because it differentiates between the OS version and the kernel version in a single view.

3. Checking the Kernel Version Only

Sometimes, knowing you are on "Ubuntu" isn't enough. You need to know the exact kernel version, especially when dealing with hardware drivers or security patches. The distribution version and kernel version are distinct entities; you can have an older OS running a newer kernel.

To check only the kernel release: uname -r

For more details, including the processor architecture and build date: uname -a

The output 5.15.0-91-generic tells you the specific build you are running. Keeping track of kernel versions is crucial for system maintenance. Over time, old kernels can accumulate and take up valuable disk space. If you need to clear out space safely, you might want to check our article on how to remove directory in linux to ensure you are deleting the right files without breaking your system.

4. The lsb_release Command

The lsb_release command is part of the Linux Standard Base (LSB) package. It is designed to provide specific distribution information. While it outputs very clean data, it is not always installed by default on minimal server builds (like some Debian or CentOS minimal images). lsb_release -a

Typical output:

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

If you get a command not found error, do not waste time trying to install it just for this one check. Stick to the cat /etc/os-release method mentioned earlier, as it is built-in and reliable.

5. Legacy Methods for Specific Distributions

If you are working with an older server (Legacy System) or a very specific distribution where the standard commands fail, you can look for distro-specific release files.

  • Debian: cat /etc/debian_version
  • RedHat / CentOS / Fedora: cat /etc/redhat-release or cat /etc/centos-release
  • Alpine Linux: cat /etc/alpine-release

6. For Developers: Checking Version Programmatically

If you are writing a deployment script or an application that needs to behave differently based on the OS, you should not rely on manual terminal commands. Instead, use the libraries provided by your programming language.

Python: The platform module in Python's standard library is excellent for this.

import platform
print(platform.platform())
# Output: Linux-5.15.0-91-generic-x86_64-with-glibc2.35

Node.js: In a Node.js environment, the os module gives you low-level system info.

const os = require('os');
console.log(os.type()); // Linux
console.log(os.release()); // 5.15.0-91-generic

When building applications that depend on specific system configurations, it is often better to manage these differences using configuration management rather than hard-coding checks. You can learn more about managing these configurations effectively in our guide on how to use environment variables.