- How to Find Linux Distribution Release Name and Version
- Check Linux Distribution Information
- Install lsb-core in Linux Distributions
- Get Linux Distribution Information
- 5 Linux Commands to Check Distro Name and Version
- 1. lsb_release
- 2. /etc/*-release files
- 3. cat /proc/version
- 4. uname -a
- Portable command
- One Comment
- 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 to Find Linux Distribution Release Name and Version
There are many commands in Linux to get the same information and one such command is the lsb_release, which is used to get the Linux distribution-related information such as OS name, code name, release information.
In some Linux distributions, the lsb_release command will be available to use and in some distributions, you have to install it, as this command is part of the LSB-core package.
Check Linux Distribution Information
To check if the lsb_release command is installed run the following command.
$ which lsb_release /usr/bin/lsb_release
In some distributions like Ubuntu, this command is already available to use but you will get the following error when you try to use some flags.
$ lsb_release -v No LSB modules are available.
Install lsb-core in Linux Distributions
To fix this you need to install the lsb-core package. Depending upon the distribution you are using run the following commands to install the lsb-core package.
------- On Debian/Ubuntu ------- $ sudo apt-get update $ sudo apt-get install lsb-core ------- On Arch/Manjaro ------- $ pacman -Syu lsb-release ------- On RHEL/CentOS ------- $ sudo yum update $ sudo yum install redhat-lsb-core ------- On Fedora ------- $ sudo dnf update $ sudo dnf install redhat-lsb-core ------- On SUSE ------- $ sudo zypper update $ sudo zypper install lsb-core
Get Linux Distribution Information
Once installed, try to run the lsb_release command again.
To get the list of available options you can refer to the man page or «-h» flag.
$ man lsb_release $ lsb_release -h
To check the description, about your distribution use the ‘-d’ flag.
To check the version information using the ‘-r’ flag.
$ lsb_release -r Release: 20.04
Every distribution comes with a code name. For example, Ubuntu 20.04 comes with the name “Focal Fossa”. To get the name use the ‘-c’ flag.
$ lsb_release -c Codename: focal
You can get all the information by using the ‘-a’ flag.
If you look at the output so far it is in key-value pair. You can just display the value alone by using the ‘-s’ flag.
$ lsb_release -i Distributor ID: Ubuntu $ lsb_release -is Ubuntu
That’s it for this article. The lsb_release is a simple command to get information about your distribution.
5 Linux Commands to Check Distro Name and Version
When working with an unknown server, the first task of a sys admin is to gather some information about the system, like what OS is it running, what version, what services are running and so on.
And there is no single command that can detect distribution specific information consistently across all linux distributions.
The command is different across Debian, CentOS and ArchLinux.
So in this post we are listing out some common commands that are used to detect distro specific information on linux. This includes the distro name and version.
1. lsb_release
The lsb_release command prints out distribution specific information about a linux distro.
On Ubuntu/debian based systems the command is available by default.
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 11.04 Release: 11.04 Codename: natty
The lsb_release command is also available on CentOS/Fedora based systems, if the lsb core packages are installed.
# lsb_release -a LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch Distributor ID: CentOS Description: CentOS release 6.4 (Final) Release: 6.4 Codename: Final
2. /etc/*-release files
The /etc directory contains a couple of files that contains information about the distribution. The following files are present on Ubuntu/Debian based systems.
/etc/issue /etc/issue.net /etc/lsb-release /etc/os-release
$ cat /etc/issue Ubuntu 13.10 \n \l
$ cat /etc/issue.net Ubuntu 13.10
$ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=13.10 DISTRIB_CODENAME=saucy DISTRIB_DESCRIPTION="Ubuntu 13.10"
$ cat /etc/os-release NAME="Ubuntu" VERSION="13.10, Saucy Salamander" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 13.10" VERSION_ID="13.10" HOME_URL="http://www.ubuntu.com/" SUPPORT_URL="http://help.ubuntu.com/" BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
The file os-release contains a whole lot of information about the system.
CentOS/Fedora based systems contain similar files but with different names.
/etc/centos-release /etc/lsb-release /etc/redhat-release /etc/system-release
# cat /etc/centos-release CentOS release 6.4 (Final)
# cat /etc/lsb-release LSB_VERSION=base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
# cat /etc/redhat-release CentOS release 6.4 (Final)
# cat /etc/system-release CentOS release 6.4 (Final)
Note that the lsb specific command and files are not present on CentOS by default. The redhat-lsb-core packages have to be installed to make lsb available. The /etc/lsb-release file does not print the distro information in a simple format.
Fedora contains the /etc/os-release file, similar to ubuntu
$ cat /etc/os-release NAME=Fedora VERSION="18 (Spherical Cow)" ID=fedora VERSION_ID=18 PRETTY_NAME="Fedora 18 (Spherical Cow)" ANSI_COLOR="0;34" CPE_NAME="cpe:/o:fedoraproject:fedora:18"
3. cat /proc/version
The /proc/version file contains information about the kernel and some indication about the distro.
On a typical Ubuntu system the contents look like this
$ cat /proc/version Linux version 2.6.38-13-generic ([email protected]) (gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4) ) #52-Ubuntu SMP Tue Nov 8 16:53:51 UTC 2011
On a typical CentOS system the output looks as follows
# cat /proc/version Linux version 2.6.32-358.11.1.el6.x86_64 ([email protected]) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) ) #1 SMP Wed Jun 12 03:34:52 UTC 2013
As can be seen above, the version information about the distro is not very clear, although it might be possible to deduce the distro in use.
Output on a RHEL 5 system
# cat /proc/version Linux version 2.6.18-028stab070.14 ([email protected]) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) #1 SMP Thu Nov 18 16:04:02 MSK 2010
4. uname -a
The uname command can also indicate which linux distro is in use, but gives very little information about it.
On Ubuntu, uname can clearly indicate the distribution name.
$ uname -a Linux enlightened-desktop 2.6.38-13-generic #52-Ubuntu SMP Tue Nov 8 16:53:51 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
However on CentOS, the exact distro name is not revealed.
# uname -a Linux dhcppc3 2.6.32-358.11.1.el6.x86_64 #1 SMP Wed Jun 12 03:34:52 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Instead it reports the base distro name EL (Redhat).
Portable command
The following is an attempt to get a portable command for checking distro info across different linux systems.
$ cat /etc/[A-Za-z]*[_-][rv]e[lr]* squeeze/sid DISTRIB_ID=Ubuntu DISTRIB_RELEASE=11.04 DISTRIB_CODENAME=natty DISTRIB_DESCRIPTION="Ubuntu 11.04"
A simpler approach to make a portable command would be like this
$ lsb_release -a || cat /etc/redhat-release || cat /etc/*-release || cat /etc/issue
If one option fails, the command moves to the next one, until one of them works. The above command is not a well tested one and is expected to work fine only on ubuntu/debian and centos/fedora based systems.
That would print all unique lines from all /etc/*-release files. Works well on most distros.
A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected] .
One Comment
- Tony August 10, 2021 at 10:10 pm Hi, Nice article.
I personaly use this command in one of my scripts: (lsb_release -a 2>/dev/null || cat /etc/redhat-release || cat /etc/*-release || cat /etc/issue) | grep -i “centos\|ubuntu\|red *hat\|fedora\|debian\|slackware\|suse\|arch\|deepin\|kubuntu\|alpine” -o | sort -f | uniq -i -u It’s not getting all the Distributions out there, but enough for my use. Cheers,
Tony
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.