CMake is a set of cross-platform tools for building programs from source code on different compilers and operating systems. It doesn’t directly build, but only generates a Makefile, which will then be executed by the make command.
If the cmake utility is not installed on Linux, then when you run the compile command, you will receive an error:
cmake: command not found
Try to manually run the cmake command with an absolute path:
/usr/bin/cmake --version
Make sure the path to the directory with the cmake command is set in the $PATH environment variable:
echo $PATH
If necessary, add the path to $PATH.
Let’s take a look at how to install the CMake command on different Linux distros.
To install CMake on Ubuntu and Debian (and other DEB systems), run:
sudo apt-get update
sudo apt-get install cmake
Alternatively, you can install the build-essential meta-package, which includes a complete set of compilation tools, including cmake:
sudo apt-get install build-essential
On RPM distros (CentOS/RHEL/Debian) you can install cmake using the package manager:
dnf install cmake
You can also download and install the latest cmake from the source files on any Linux distribution:
wget https://github.com/Kitware/CMake/releases/download/v3.22.1/cmake-3.22.1-linux-x86_64.tar.gz
Extract the archive:
tar -zxvf cmake-3.22.1-linux-x86_64.tar.gz
Go to the folder:
cd cmake-3.22.1-linux-x86_64
And run the commands:
./bootstrap
Make
Build cmake:
make install
Make sure cmake is successfully installed on your host by displaying its version:
cmake --version