When you install CMake with APT, you’ll notice it installs an older version. This tutorial shows you how to install the latest version so that you can build software that requires newer CMake features.
Remove old version
Before we begin, you’ll want to remove any previous versions of CMake that were installed with APT. Run the following commands to remove it:
sudo apt remove --purge cmake
Install the latest CMake
As of writing the latest version of CMake is 3.20.2 which can be installed using one of the following two options:
Option 1: Use Snappy
Using the Snappy package manager is the quickest and easiest way to install the latest version of CMake on Ubuntu Linux.
Install it with Snappy by running the following command:
sudo snap install cmake --classic
You can check to see if it’s installed by running:
Option 2: Install from source
The second option is to download the source code from the CMake website and compile it on your Linux machine. This can take much longer, depending on how powerful your machines processor is.
Run the following commands to download, compile and install CMake:
(Note: replace v3.20.2 with the version you want to install, see the CMake download page for a list of versions)
sudo apt install build-essential libssl-dev
tar -zxvf cmake-3.20.2.tar.gz
sudo make install
That’s it, now you have the latest version of CMake installed on your Ubuntu Linux machine, as you can see from the output of the
cmake --version command below.