How to Install CMake on Rocky Linux 9/8

CMake is an open-source, cross-platform family of tools designed to build, test, and package software. It controls the software compilation process using simple platform and compiler-independent configuration files, making it an indispensable tool for developers. CMake supports complex directory hierarchies and applications that depend on multiple libraries, offering a streamlined process for managing builds and dependencies.

The following guide will demonstrate the steps to install CMake on Rocky Linux 9 or 8 using command-line commands. The installation methods involve using the default AppStream repository or, as an alternative, downloading and compiling the latest version’s source binary.

Update Rocky Linux Before CMake Installation

First, make sure your system is up-to-date by running an update on all existing packages.

sudo dnf upgrade --refresh

Select the CMake Installation Method

Method 1: Install CMake via Rocky Linux Default Appstream

The first method recommended for most users is to install CMake from the appstream. This version is the default and is recommended for most users unless you need a specific version or the latest version, in which case you must use the compile method. To begin the installation, use the following command.

sudo dnf install cmake

Once CMake is installed, you can confirm the installation by checking the version of CMake.

cmake --version

Method 2: Install CMake via Source Archive

The second method for installing CMake is downloading and compiling the source code. This method allows you to install the latest version of CMake. However, it comes with the responsibility of remembering to download and re-compile the source code for updates.

Before beginning the installation process, you must install some required dependencies on your system. You can do this by running the following command.

sudo dnf install gcc gcc-c++ openssl-devel bzip2-devel libffi-devel zlib-devel make -y

First, visit the Github releases page and grab the latest version link.

Next, download the archive using the wget command.

wget https://github.com/Kitware/CMake/releases/download/v3.25.2/cmake-3.25.2.tar.gz

Note: This is an example command only; do not copy it. Visit the CMake release page to download the latest source, as the example will be outdated.

Extract the archive using the following command.

tar -zxvf cmake-{version number}.tar.gz

Change the directory into the extracted folder using the following command.

cd cmake-{version number}

In the next step, you will run the Bootstrap script. It is essential to ensure that all the required dependencies mentioned earlier are installed, as not doing so may cause issues.

./bootstrap

Once the Bootstrap script is completed, use the make command to build the CMake package. This process may take several minutes.

make

This process may take several minutes, so you may want to take a break or grab a drink while you wait.

The next step is to install CMake using the “make install” command.

sudo make install

Once completed, you can verify the installation by checking the version of CMake using the following command.

cmake --version

Example output:

cmake version 3.25.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Conclusion

Installing CMake on Rocky Linux is straightforward. There are two main methods: using the dnf package manager via the app stream or compiling from the source. The app-stream method is recommended for most users due to its simplicity and ease of updating. However, compiling from the source is ideal for those needing the latest version or a specific version of CMake. After installation, always verify the version to ensure it’s correctly installed.

For further reading, visit CMake’s official documentation.

Leave a Comment