Installing Latest CMake from Source on Linux Distro

As I had mentioned in the previous post, I have been working on setting up a Linux VM to test my upcoming OpenGL tutorial series. As part of that, I was trying to setup CMake on the VM, so that I can sort out cross platform builds.

However, default CMake version available in Ubuntu repository was 3.10.2 and I needed at least 3.15 to fully utilize some of the latest features.

If you are on Ubuntu, Snap has latest CMake available. Install it with
sudo snap install cmake --classic # version 3.18.2

At this point, there were two options:

  • Either download pre-built binaries
  • Or build from source

Remove Existing CMake #

If any version of CMake was installed earlier, first remove that completely...

sudo apt purge --auto-remove cmake

Build from Source it is #

Feel free to download binaries if you want, from official CMake download page.

I decided to go with build from source. This works for any other similar tools as well.

Download latest source code from the same download page and extract

$ wget https://github.com/Kitware/CMake/releases/download/v3.18.2/cmake-3.18.2.tar.gz
$ tar -xvzf cmake-3.18.2.tar.gz

Change directory to the extracted one, build and install CMake ...

./bootstrap
make -j$(nproc)
sudo make install

If you get an error related to OpenSSL, download and install OpenSSL from source. The process is similar to what we are doing with CMake and explained here.

BAM! Unexpected Recursion #

Hofstadter by xkcdHofstadter by xkcd

When you come out of it #

Confirm CMake version

$ cmake --version

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

And done!