4 Ways to Check CentOS Version in Linux Command Line
Here are several ways you can check the version of CentOS Linux distribution running on your machine.
CentOS is a great OS when comes to server software because they have longer support cycle and great stable software in the repositories and a larger community. To know more about why CentOS is better, check out this page.
It happens most of the time when installing or selecting a software package, one needs to know the version of the CentOS running in their systems to avoid dependency mismatch and other issues.
In this tutorial, I’ll show you some ways by which you can check the version of the CentOS.
How to Check CentOS Version
To check CentOS version, you can use a command like this:
lsb_release -d
The result will give you the CentOS version number.
linux@handbook:~$ lsb_release -d
Description: CentOS Linux release 7.14.1234
Before we see other methods to check CentOS version, let’s first understand the version number and what those number means.
CentOS version consists of three parts, which can be best understood with an example. Consider the version:
7.14.1234
- 7-major release: This is the most important version number because software packages developed for one version may not be supported in other versions. This is because newer versions will have some bugs fixed which are not in new versions and also they will have new features, new packages, and new hooks into the system. So, there will be a problem when running the software intended for other versions and hence can mess up the system.
- 14-minor release: These are less important, but they are crucial for maintaining major security updates and a few new features.
- 1234-build number: This is a version for distributing the software with minor security updates and bug fixes. This doesn’t affect the software versions running on the system that much.
Method 1: Using hostnamectl
The hostnamectl command can be used to query and set the hostname for the system. I also display the Version number of the OS running in the system. This Command displays only the major version number.
sudo hostnamectl
Your output will be similar to like the one below.
Method 2: Using rpm package manager
Since os itself considered as a package by most package managers one can query the package manager(rpm in this case) to find the version of the OS.
rpm -q centos-release (or)
rpm --query centos-relase
where:
- rpm is the package manager
- -q or –-query is the option for querying
- centos-release is the package that we want to query on
Note: If you need to check any other software replace centos-release with <packagename>.
Result of the above will be similar to the one below:
Method 3: Refer the files /etc/*release
Every Linux OS hosts teh important and configuration details about itself and packages in /etc/ directory. And so does centOS.
If you issue ls /etc/*release
, following files will be listed.
- centos-release
- os-release
- redhat-release
- system-release
One can guess by the name of the files, they carry information about the system release. You can manually open the files using any text editor and examine the files for version information or cat command can be used to see the contents of the files. If you don’t know what is cat
or you want to brush up your cat
skills, Check out this detailed guide on using cat command.
cat /etc/*release
Result of the command will be similar to below:
Method 4: Using lsb_release tool
lsb release command displays important lsb (linux standard base) information and distribution information. But this tool is available inside the package redhat-lsb.
Install the package in your system using the below command to continue (if you don’t have already).
sudo yum install redhat-lsb
As you might have noticed, you need to be a sudoer for running this command as you are installing a package. If you are a sudoer and you want to give someone sudoer rights, learn how to create sudo user. If you are not a sudoer, try contacting your system admin.
After installing the package, run the below command:
lsb_release -d
where,
- -d is the option to display a description of the Linux distribution
The result will be similar to the one below:
This lsb_release
command can be used in other distributions as well. For example, you can run it on Debian to check the Debian version.
Congratulations!. By now, you know various ways by which version number of the CentOS can be found.
I hope you found this article useful. If you have any suggestions or comments, feel free to drop them below.
LHB Community is made of readers like you who share their expertise by writing helpful tutorials. Contact us if you would like to contribute.