How to Install Latest CMake on CentOS

CMake is an open-source, cross-platform family of tools designed to build, test and package software. CMake is used to control the software compilation process using native platform and compiler-independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice. 

We will use the currently latest stable version 3.22.2 of CMake as an example to show how to install CMake on CentOS. The full process has been tested as working on CentOS 7, CentOS 8, and CentOS Stream 8. Problems that you may encounter during compilation are also specified in detail.

If you need CMake to compile and install software on CentOS, but the CMake version installed by package manager Yum or DNF does not meet the requirement, you can follow this article to quickly install latest CMake in best practices.

A root user role is required to follow the commands in this article. If you are not the root user, please make sure to add “sudo” before each command, or switch to the root user by command below:

sudo -s

We will use yum command for any package related operation. Please note that on CenOS 8, CentOS Stream 8 and later versions of CentOS, yum command is a symbolic link to dnf binary and was replaced by dnf command.

1 Download CMake

We have three ways to install latest version of CMake: use a package manager (like YUM/DNF) to download and install automatically from custom repositories, or install manually from generic binary distribution, or install manually from source compilation.

All these ways have pros and cons. Using package manager is easy and fast, but it is usually not the latest version that installed, and it cannot be customized for additional features. Compiling from source supports customization for various functionalities, but you need to manage all the dependencies by yourself.

We will install CMake from generic binary distribution as a compromised choice. This way we can get the latest version installed, and installation files will be isolated from system built-in software libraries, and we do not need to spend too much time compiling the source code.

CMake has multiple versions, including but not limited to Release Candidate and Latest Release. We recommend to use the Latest Release, which is the version used for examples in this article.

We will get the download link of latest stable distribution package from:

First let us change the directory to system local source folder, then we will download the latest stable CMake binary distribution package by curl command using the link we got:

cd /usr/local/src
curl -LO

2 Install CMake

After CMake binary distribution package is downloaded, run the following two commands to unpack the package, and move it to the program files directory with folder name renamed to “cmake” (/usr/local/cmake):

tar -xvf cmake-3.22.2.tar.gz
mv cmake-3.22.2 /usr/local/cmake

That’s it. We have finished the CMake installation. If this is your first time to install CMake, to make it easier to execute CMake commands later, please add the path of CMake executable file to system environment variable PATH by commands below:

echo 'export PATH="/usr/local/cmake/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Now you may check the CMake version:

cmake --version

3 Upgrade CMake

To upgrade CMake to a new version released in future, just follow all steps in this guide once more. 

Leave a comment

Your email address will not be published. Required fields are marked *