How to install cmake?

CMake is a cross-platform tool for building, testing and packaging software.

If you’ve been writing C or C++ (or maybe Fortran) you probably had to, at some point, use cmake to package your software.

If you’re a Linux user, you’d normally just need to run:

1
sudo apt-get install -y cmake

to install it. But sometimes, the version that you can install from the official repository is not the one you need.

Therefore, you will probably need to proceed with a manual installation. But before you do that, check the current version to see whether is the one you expect or not:

1
cmake --version
Note
These instructions should work for Debian based distros and macOS.

Remove the current install:

1
sudo apt-get -y purge --auto-remove cmake

Download the latest stable release, e.g v3.19.2 (do not download the binary/dmg distribution, but the Linux/Unix source):

1
wget https://github.com/Kitware/CMake/releases/download/v3.19.2/cmake-3.19.2.tar.gz

Unzip the archive:

1
tar -xzvf cmake-3.16.4.tar.gz

Build and install it:

1
2
3
4
cd cmake-3.16.4
./bootstrap
make -j$(nproc)
sudo make install

Verify the installation:

1
cmake --version

If you see something like:

1
2
cmake version 3.19.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).

you’re good to go.

For other platforms, check the official install guide.