Check CentOS Version

There are several ways on how to check what version of CentOS is running on your system. The simplest way to check for the CentOS version number is to execute the cat /etc/centos-release command. Identifying the accurate CentOS version may be required to help you or your support team to troubleshoot your CentOS system.

The CentOS version consists of three release versions as illustrated below:
Identifying the CentOS Release version
The CentOS version consists of Major, Minor and Asynchronous Release number.

What is the command to check CentOS version?

The following table contains most common and recommended ways on how to check CentOS version on your CentOS Linux server or desktop.

Command Description
$ rpm -q centos-release CentOS version valid for CentOS 6 and higher. Causes to reveal major, minor and asynchronous CentOS version.
$ lsb_release -d Requires redhat-lsb package to be installed before execution.
$ cat /etc/centos-release Linux cat command to output content of the /etc/centos-release to query CentOS version. Works with CentOS 6 and higher.


Alternative commands to check CentOS version

In case the above-provided commands did not help you to obtain the CentOS version number you may try the following alternative commands.

Although available only for CentOS version 7 and above the hostnamectl command might provide you with a significant clue about your OS version number:
$ hostnamectl 
   Static hostname: localhost.localdomain
         Icon name: computer-vm
           Chassis: vm
        Machine ID: fe069af6a1764e07be909d7cf64add99
           Boot ID: b81bb73dc549484c8927e830e149eb55
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-862.6.3.el7.x86_64
      Architecture: x86-64
For more answers try to query all release files within the /etc directory:
$ cat /etc/*elease
CentOS Linux release 7.5.1804 (Core) 
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"

CentOS Linux release 7.5.1804 (Core) 
CentOS Linux release 7.5.1804 (Core)
The system you are running may have macros defined which can help you in identifying the major release version of your CentOS Linux server. Try the following:
$ rpm --eval '%{centos_ver}'
7
Lastly, your GRUB boot manu may provide some answers. This is not most reliable way to check for CentOS version however it may provide you with some clues:
# grep -w menuentry /boot/grub2/grub.cfg /etc/grub2.cfg
/boot/grub2/grub.cfg:menuentry 'CentOS Linux (3.10.0-862.6.3.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-693.el7.x86_64-advanced-176eba78-e8ec-475d-9086-0d582fcd4305' {
...
 


Using Programming to check CentOS version

In case you wish to program your way to check the CentOS version automatically you have multiple options available. This section will list some basic examples of how to check CentOS version using Bash script and Python programming language.

Bash Script to check CentOS version

The following bash script can be used to obtain the CentOS version number given that the /etc/centos-release file exists and is populated. Serves as an example, modify wherever appropriate:
#!/bin/bash

full=`cat /etc/centos-release | tr -dc '0-9.'`
major=$(cat /etc/centos-release | tr -dc '0-9.'|cut -d \. -f1)
minor=$(cat /etc/centos-release | tr -dc '0-9.'|cut -d \. -f2)
asynchronous=$(cat /etc/centos-release | tr -dc '0-9.'|cut -d \. -f3)

echo CentOS Version: $full
echo Major Relase: $major
echo Minor Relase: $minor
echo Asynchronous Relase: $asynchronous
Output:
$ ./check-centos-version.sh 
CentOS Version: 7.5.1804
Major Relase: 7
Minor Relase: 5
Asynchronous Relase: 1804

Python program to check CentOS version

The following python script will output the distribution name along with the OS version number:
#!/usr/bin/python

import platform
print platform.linux_distribution()
Output:
$ python check-centos-version.py 
('CentOS Linux', '7.5.1804', 'Core')
If you have made a minimal CentoOS installation you can always install Graphical User interface as part of group packages. Let's first list all available package groups on the system:
# yum group list
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: centos.mirror.crucial.com.au
 * extras: centos.mirror.crucial.com.au
 * updates: centos.mirror.crucial.com.au
Available environment groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done

Objective

The objective is to first configure a basic ProFTPD server on CentOS 7. Once we have a basic FTP server setup, we will then add FTP passive mode and increase security by adding Transport Layer Security ( TLS ).

Lastly, we add an optional anonymous configuration to allow anonymous user to login to FTP server without username and password.

Operating System and Software Versions

  • Operating System: - CentOS Linux release 7.5.1804
  • Software: - ProFTPD Version 1.3.5e

Requirements

Privileged access to your Ubuntu System as root or via sudo command is required.

Difficulty

MEDIUM

Conventions

Objective

The objective is to install Python 3 on CentOS 7 with Software Collections (SCL).

Operating System and Software Versions

  • Operating System: - CentOS 7 or higher

Requirements

Privileged access to your Ubuntu System as root or via sudo command is required.

Difficulty

EASY

Conventions

Objective

The objective is to install VirtualBox Guest Additions on CentOS 7 Linux

Operating System and Software Versions

  • Operating System: - CentOS Linux release 7.5.1804 (Core)

Requirements

Privileged access to your Ubuntu System as root or via sudo command is required.

Difficulty

EASY

Conventions

ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME or create a JOB ALERT on LinuxCareers.com job portal.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.