How to Check Linux Distribution and Version Using Terminal
Table of Contents
Introduction
When people talk about Linux, they usually mean a Linux distribution. Technically speaking, Linux is a kernel and the core of the operating system and allows you to run different programs on top of it. It is pretty much useless by itself and is the foundation of a Linux distribution. The Linux distribution is the collection of software that makes up the operating system, including the Linux kernel, utilities and services.
Some of the most popular Linux distributions are Ubuntu, Debian, Fedora, Red Hat, Arch Linux, Kali Linux, Linux Mint, CentOS, OpenSUSE, etc. Each distribution (or a distro) manages software and updates in a different way, so it's important to know which one you are using.
Check Linux Distribution and Version
There are a few reasons why you might want to check your Linux distribution and version. Maybe you're trying to determine if your system is up to date, or you're troubleshooting a problem and need to know which version of Linux distribution you're running. Either way, it's easy to check your Linux distribution and version using the command line.
Using /etc/os-release File
The /etc/os-release
and /usr/lib/os-release
files contain operating system identification data. Any system running systemd should have /etc/os-release
, as this file is specified as part of systemd.
Note: The /etc/os-release
file contains information about the operating system, and takes precedence over the /usr/lib/os-release
file. This means that you should check for the /etc/os-release
file first, and if it exists, use the information from that file. If the /etc/os-release
file is missing, then you should fall back to using the /usr/lib/os-release
file. Use man os-release
for more details.
Use either cat
, more
or less
command to view os-release file:
cat /etc/os-release
It should output something like this:
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
To get some specific information, you can use the grep
or egrep
command.
grep '^PRETTY_NAME' /etc/os-release
egrep '^(NAME|VERSION)' /etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
Use =
for exact match:
grep '^PRETTY_NAME=' /etc/os-release
egrep '^(NAME|VERSION)=' /etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
Info: The /etc/os-release
file is also present in the Docker images of a lot of distributions including Alpine.
Using lsb_release Command
The lsb_release
command prints LSB (Linux Standard Base) and distribution specific information on the terminal. If it is not installed by default on your system, use your system package manager to install the lsb-release
package.
Install lsb-release Package
Make sure you have sudo privileges to install the package.
# On Arch Linux
sudo pacman -S lsb-release
# On Debian, Ubuntu
sudo apt-get install -y lsb-release
# On SUSE/OpenSUSE
sudo zypper install lsb-release
# On CentOS/RHEL 7
sudo yum install redhat-lsb-core
# On CentOS/RHEL 8 and 9, Fedora
sudo dnf install redhat-lsb-core
# lsb_release command is provided by the package βredhat-lsb-coreβ
Check Version Using lsb_release
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy
Check lsb_release
command options using lsb_release --help
.
Warning: lsb-release
package may not be present in the Docker images of many distros.
You can also use the lsb-release file:
cat /etc/lsb-release
Using /etc/issue File
The /etc/issue
file contains a prelogin message or system identification that gets printed before the login prompt.
cat /etc/issue
Ubuntu 22.04.1 LTS \n \l
Using hostnamectl Command
The hostnamectl
is also part of systemd and can be used to query and change the system hostname and related settings. This command prints Linux distribution as well as Linux kernel version.
hostnamectl
...
Operating System: Ubuntu 22.04.1 LTS
Kernel: 5.10.102.1-microsoft-standard-WSL2
Architecture: x86-64
Note: For hostnamectl
command to work, system must be booted with systemd as init system.
Using /etc/*release File
If the commands above don't work for you, it's probably because you're using a very old and outdated Linux distribution. In that case, you can try any of the below commands to print the system's release or version file.
# Use any one
cat /etc/*release
cat /etc/*version
Using uname Command
The uname command prints the system information like the kernel name, release, version, architecture.
To print the kernel release:
uname -r
Check kernel name and architecture:
uname -sm
If you want to display all the details, you can use uname -a
.
# uname -srm
Linux 5.10.102.1-microsoft-standard-WSL2 x86_64
Using /proc/version File
Another way to check Linux kernel version is to use /proc/version
file:
cat /proc/version
This command outputs something like this:
Linux version 5.10.102.1-microsoft-standard-WSL2 (oe-user@oe-host) (x86_64-msft-linux-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Wed Mar 2 00:30:59 UTC 2022
Conclusion
There are quite a few ways to check distribution name and version and Linux kernel version. On most of the distributions, you can use /etc/os-release
file to check distribution information and uname -r
for kernel version.
If you are using Linux distribution with a desktop environment, you may check the distribution and version through the graphical user interface.
Comments