One of the very first questions a Linux user asks is about confirming the release (OS version) in use. Knowing release helps with highlighting software dependencies and compatibilities, confirms availability of certain features in your OS and simplifies the process of system administration – certain releases have a preferred set of commands for day-to-day management.
With CentOS being a rather popular server grade Linux distro, I can see that many visitors of my blog look for the same guidance quite regularly: check CentOS version. This article introduces 5 of the most common ways to do just that.
1. Inspect /etc/system-release
Just to be super sure that you're actually looking at a CentOS distribution of Linux, I suggest you start with the /etc/os-release file. As shown below, it will help you with confirming your Linux distro and its major release version (CentOS and 7 in my case):
greys@s5:~ $ cat /etc/os-release NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7"
Now that we're sure it's CentOS, let's look into the /etc/centos-release file – this will show you the full release version of your operating system:
greys@s5:~ $ cat /etc/centos-release CentOS Linux release 7.4.1708 (Core)
Interesting: if you're coming from RedHat infrastructure, you'd normally be looking for /etc/redhat-release file. That's okay and the good news is this will still work in CentOS:
greys@s5:~ $ cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core)
In fact, if you look at the /etc/redhat-release file on a CentOS server closely, you'll notice that it is a symbolic link to /etc/centos-release:
greys@s5:~ $ ls -ald /etc/redhat-release lrwxrwxrwx. 1 root root 14 Sep 18 2017 /etc/redhat-release -> centos-release
2. Use hostnamectl to confirm Linux release
Provided that you're running a recent enough version of Linux, you should have the hostnamectl command installed.
Among other things, hostnamectl provides easy access to the OS release information and Linux kernel version:
greys@s5:~ $ hostnamectl Static hostname: s5.ts.im Icon name: computer-desktop Chassis: desktop Machine ID: 5f7e36c18a974f06ae94ddaaf11d71e8 Boot ID: 337e48b00fed4abe9ab929fed5aa6018 Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-693.11.6.el7.x86_64 Architecture: x86-64
3. Confirm CentOS version with rpm
Next option you have is to use the RPM package manager to query a special package named centos-release. It will include the exact CentOS release version right in its full package name:
greys@s5:~ $ rpm -qa centos-release centos-release-7-4.1708.el7.centos.x86_64
if you're using RedHat, just do the same for the redhat-release package.
4. Confirm CentOS version using Linux kernel version
There are many ways to confirm your Linux kernel version, like uname command:
greys@s5:~ $ uname -r 3.10.0-693.11.6.el7.x86_64
Using the kernel version number – 3.10.0-693 in my example – you can confirm the CentOS release using one of the public version information pages, like the CentOS wikipedia page.
Once you browse to the CentOS wikipedia page, just search for the kernel version number and it should find something like this for you, confirming CentOS version to be 7.4-1708:
5. Use lsb_release command to confirm Lunux release
Linux Standard Base (LSB) is a joint project by major Linux vendors to standardise configuration and usage of Linux distros. Amonth other things, it provides the lsb_release command that can help you check CentOS version.
Most likely, you'll have to install it first:
greys@s5:~ $ yum install redhat-lsb-core ...
greys@s5:~ $ lsb_release -d Description: CentOS Linux release 7.4.1708 (Core)