- How do I find out what version of Linux I’m running?
- 9 Answers 9
- How to Check OS Version from Command Line
- Checking the operating system version
- Final thoughts
- About the author
- Sidratul Muntaha
- How to Find Which Linux Version You Are Running
- Find Linux distribution details
- Method 1: Use /etc/os-release file
- Method 2: Use hostnamectl command
- Method 3: Use lsb-release command
- Bonus Tip: Find Linux kernel version
How do I find out what version of Linux I’m running?
Is there a way to determine what version (distribution & kernel version, I suppose) of Linux is running (from the command-line), that works on any Linux system?
I’d just like to point out for the record how stupid it is that this is a question which needs asking. This is really quite an indictment on the state of every linux distro.
9 Answers 9
The kernel is universally detected with uname :
$ uname -or 2.6.18-128.el5 GNU/Linux
There really isn’t a cross-distribution way to determine what distribution and version you’re on. There have been attempts to make this consistent, but ultimately it varies, unfortunately. LSB tools provide this information, but ironically aren’t installed by default everywhere. Example on an Ubuntu 9.04 system with the lsb-release package installed:
$ lsb_release -irc Distributor ID: Ubuntu Release: 9.04 Codename: jaunty
Otherwise, the closest widely-available method is checking /etc/something-release files. These exist on most of the common platforms, and on their derivatives (i.e., Red Hat and CentOS).
$ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=9.04 DISTRIB_CODENAME=jaunty DISTRIB_DESCRIPTION="Ubuntu 9.04"
But Debian has /etc/debian_version :
$ cat /etc/debian_version 5.0.2
Fedora, Red Hat and CentOS have:
Fedora: $ cat /etc/fedora-release Fedora release 10 (Cambridge) Red Hat/older CentOS: $ cat /etc/redhat-release CentOS release 5.3 (Final) newer CentOS: $ cat /etc/centos-release CentOS Linux release 7.1.1503 (Core)
$ cat /etc/gentoo-release Gentoo Base System release 1.12.11.1
I don’t have a SUSE system available at the moment, but I believe it is /etc/SuSE-release .
Slackware has /etc/slackware-release and/or /etc/slackware-version .
Mandriva has /etc/mandriva-release .
For most of the popular distributions then,
will most often work. Stripped down and barebones «server» installations might not have the ‘release’ package for the distribution installed.
Additionally, two 3rd party programs you can use to automatically get this information are Ohai and Facter.
Note that many distributions have this kind of information in /etc/issue or /etc/motd , but some security policies and best practices indicate that these files should contain access notification banners.
How to Check OS Version from Command Line
Linux is a powerful operating system that’s free and open-source. Because it’s open-source, Linux is available in numerous variations. Generally, each variant is known as a Linux distribution (also known as Linux distro). You may have already heard the name of the big ones like Ubuntu, Debian, RHEL, Fedora, Arch Linux, SUSE, etc.
Knowing the name and version of a distro is vital for users and administrators. The information is important in numerous situations like installing new apps or features, troubleshooting, etc. This guide will demonstrate how to check the OS version from the command line on Linux.
Checking the operating system version
Here are some of the simplest ways of checking the operating system version. Almost all of these methods should apply to any Linux distro. These methods utilize the built-in tools and feature Linux comes with.
Checking OS version from /etc/os-release
In Linux, the os-release file contains various information about the system. There are two copies of the file at two different locations.
Interestingly, the file located at /etc/os-release will take precedence over /usr/lib/os-release.
It contains information in the format of a newline-separated list of various variables. It contains info like OS name, version, version ID, builds ID, etc.
To check the content of the os-release file, run the following command.
Note that the output will vary from one Linux distro to another. This file will only be available if the OS uses the systemd as the init system.
Here are some examples that fine-tune the content of os-release to print only specific details. The following command will print only the version and name of the OS.
To check the version of the OS only, run the following command instead.
Checking OS version using lsb_release
The lsb_release tool provides certain LSB (Linux Standard Base) and distro-specific info. Generally, lsb_release is used in the following format.
Here, the flag “-a” tells lsb_release to print all the info about the OS it can provide. Alternatively, you can print a minimal report using the flag “-s” or “–short”. It will omit the headers in the output.
This tool also supports printing one specific piece of information at a time. For example, to print only the OS description, use the flag “-d” or “–description”.
To display the codename of the current OS, use the flag “-c” or “–codename”.
The man page contains an in-depth description of all the available options.
Checking OS version using hostnamectl
The hostnamectl command is responsible for managing the Linux system hostname and related settings. It can also print a host of info on the system and operating system.
Checking OS version using uname
Similar to lsb_release and hostnamectl, uname is another tool to report various info about the machine and operating system. However, the output is a bit more disorganized compared to hostnamectl output.
To print all the information about the system, run the following uname command. Here, the flag “-a” tells uname to print all the supported info.
We can also tell uname to print only specific detail. For example, the flag “-v” or “–kernel-version” will print the kernel version.
The following uname command will print the operating system label.
For all the available options and their explanations, check the man page.
Checking OS version from /etc/issue
The file /etc/issue stores system identification information. It’s generally shown before you’re prompted to log in to your account. Check the content of the file.
Checking OS version using /proc/version
It’s a text file that includes information about the Linux kernel.
Checking OS version using /etc/*release
If none of the aforementioned methods succeeded, then it’s highly likely that you’re running a very old Linux system. If that’s the case, then we have to take advantage of a very rudimentary method of checking OS information.
Run the following command.
Here, cat will read and print the content of all the files that match the pattern. You can check what files we’re reading from.
Final thoughts
This guide demonstrates how to check the version of the Linux operating system running on the machine. Although there are many third-party tools, we can achieve it using the built-in tools and features only.
The version of a Linux operating system is an important piece of information. Generally, Linux packages are built to work with a particular Linux version in mind. Knowing the Linux version can help in troubleshooting unexpected behaviors or errors. It’s also important when a new version of the Linux distro is released. It’s simple yet crucial info to keep track of.
About the author
Sidratul Muntaha
Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.
How to Find Which Linux Version You Are Running
Logged in on a Linux system via SSH and wondering which Linux distribution is it? Here’s how to check the Linux version.
When you install a Linux distribution on your own, you know which distribution and version it is.
But if you use SSH to log in to a remote Linux server provided by an enterprise or client, you may wonder which Linux distribution and version it is.
The simplest way to check Linux version is to see the content of the /etc/os-release file:
It will show an output similar to this:
NAME="Ubuntu" VERSION="20.04.1 LTS (Focal Fossa)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.04.1 LTS" VERSION_ID="20.04" 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" VERSION_CODENAME=focal UBUNTU_CODENAME=focal
As you can see, the Linux name is Ubuntu and the version is 20.04.1.
However, that’s not the only way to know the Linux distribution details. In this beginner’s tip, I’ll show you different ways to check which Linux you are running.
Find Linux distribution details
Method 1: Use /etc/os-release file
If you are familiar with the Linux directory structure, you probably already know that /etc directory contains the core configuration files of the system.
The os-release file in the /etc directory keeps the information about the Linux distribution. It gives you the distribution name, distribution version, release name or ID.
Here’s what it displays for Alpine Linux server running on Linode infrastructure.
handbook:~# cat /etc/os-release NAME="Alpine Linux" ID=alpine VERSION_ID=3.12.0 PRETTY_NAME="Alpine Linux v3.12" HOME_URL="https://alpinelinux.org/" BUG_REPORT_URL="https://bugs.alpinelinux.org/"
As you can see, the name of Linux distribution is Alpine Linux and the distribution version is 3.12.
The content of the /etc/os-release is usually different for different distributions. Distributions often use it to provide additional information like where to get support or file bugs etc.
For example, the /etc/os-release provides more lines for CentOS Linux.
NAME="CentOS Linux" VERSION="8 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="8" PLATFORM_ID="platform:el8" PRETTY_NAME="CentOS Linux 8 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:8" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-8" CENTOS_MANTISBT_PROJECT_VERSION="8" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="8"
However, all of them provide the Linux distribution name and version so it is a pretty reliable way to know which Linux you are running. In fact, it is the most reliable way.
Method 2: Use hostnamectl command
Most Linux distributions these days use systemd. On such a system, you can use the hostnamectl command to get Linux version detail.
For the same CentOS system that you saw above, hostnamectl provides the following details:
[[email protected] ~]# hostnamectl Static hostname: localhost.localdomain Transient hostname: li2498-99.members.linode.com Icon name: computer-vm Chassis: vm Machine ID: e3fe2be3e17be3e1763bf43e8337e68b Boot ID: 33d3052bbffd44b1869bbffd4b00d26c Virtualization: kvm Operating System: CentOS Linux 8 (Core) CPE OS Name: cpe:/o:centos:centos:8 Kernel: Linux 4.18.0-147.8.1.el8_1.x86_64 Architecture: x86-64
You can see the Linux version detail in the line starting with ‘Operating System’.
The hostnamectl command is primarily used for dealing with the hostname but if it provides other details why not use it?
Method 3: Use lsb-release command
This is NOT a command that you’ll find in all Linux distributions. I think it is mostly used by Debian/Ubuntu based distributions.
You can use the lsb_release command with option -a and it will provide distribution details:
Don’t mind the No LSB modules are available line. It’s not an error of any kind.
[email protected]:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.1 LTS Release: 20.04 Codename: focal
Bonus Tip: Find Linux kernel version
Now that you know which distribution you are running, perhaps you would also like to know about the Linux kernel version running on the system.
You can get the kernel details using the uname command in any Linux distribution.
The output shows only the Linux kernel version:
handbook:~# uname -r 5.4.43-1-virt
No prizes for guessing that the above system is running on Linux kernel version 5.4.43.
I hope you find this quick tip helpful in finding Linux version detail. If you have questions or suggestions, please let me know in the comment section.