How to update cmake on Ubuntu

Lynn
2 min readJun 3, 2022

--

Due to various applications’ request, the original version of cmake needs to be updated. This article will elaborate the whole process to update cmake to any specific version.

Photo by Kristopher Roller on Unsplash

Uninstall

Here we should separate the problem into two situations according to the way you installed the current cmake.

Firstly, if the current cmake is the default version provided by Ubuntu package manager, just run

sudo apt purge --autoremove cmake

to remove all the related binary, configuration, data and dependency files which is no need anymore.

Refer to this article to fully understand the exact meaning of commands above:

Besides, if the current cmake is compiled and installed from source codes by yourself manually, chang your direcrory into the path you ran sudo make install before and run

 sudo make uninstall

Building and Installing

Go to the official cmake webpage, then download and extract the latest version. Here take cmake-3.22.1.tar.gz for example. Run

tar -xzvf cmake-3.22.1.tar.gz
cd cmake-3.22.1
./bootstrap
make -j$(nproc)
sudo make install

$(nproc) stands for your number of processing units available, and this can accelerate your process of compilation.

If get something wrong when running ./bootstrap like this:

Could not find OpenSSL. Install an OpenSSL development package or
configure CMake with -DCMAKE_USE_OPENSSL=OFF to build without OpenSSL.

It is not caused by the lack of openssl, actually run apt policy openssl and we’ll see it has already been installed in our system directory, but needs the dev package of openssl. Simply run

sudo apt install libssl-dev

Then, test your new cmake version.

cmake --version

Results of cmake -- version :

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

Some hints here:

The cmake --version command only works after open a new terminal because cmake is installed under /usr/local/bin/ by default, not usr/bin/, which can be seen by running which cmake.

Extra

Refer to this article to use cmake by alternatives.

--

--