How To Install CMake on Ubuntu 20.04

In this article, we want to teach you How To Install CMake Latest Version on Ubuntu 20.04.

What is CMake?

CMake is known as a meta-build system. It doesn’t actually build your source code: instead, it generates native project files for the target platform. For example, CMake on Windows will produce a solution for Visual Studio; CMake on Linux will produce a Makefile; CMake on macOS will produce a project for XCode, and so on. That’s what the word meta stands for: CMake builds build systems.

A project based on CMake always contains the CMakeLists.txt file. This special text file describes how the project is structured, the list of source files to compile, what CMake should generate out of it, and so on. CMake will read the instructions in it and will produce the desired output. This is done by the so-called generators, CMake components responsible for creating the build system files.

Another nice CMake feature is the so-called out-of-source build. Any file required for the final build, executables included, will be stored in a separate build directory (usually called build/). This prevents cluttering up the source directory and makes it easy to start over again: just remove the build directory and you are done.

Steps To Install CMake on Ubuntu 20.04

In this guide, you learn to install CMake from the APT repository and from the source on your server.

Before you start to complete this guide, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with Ubuntu 20.04.

Install CMake on Ubuntu 20.04 from APT Repository

The first way to install CMake is to use the APT repository. First, update your local package index with the following command:

sudo apt update -y

Then, you can use the command below to install CMake:

sudo apt install cmake

When your installation is completed, you can verify your CMake installation by checking its version:

cmake --version
Output
cmake version 3.16.3 
CMake suite maintained and supported by Kitware (kitware.com/cmake).

Install CMake on Ubuntu 20.04 from Source

If you want to install the latest release of CMake, it’s recommended to download it from the source and build it.

First, you need to install the dependencies on Ubuntu 20.04 with the following command:

sudo apt install build-essential checkinstall zlib1g-dev libssl-dev -y

Download CMake 3 on Ubuntu

Then, you need to visit the GitHub CMake Releases Page and get the latest version link and download it with the wget command:

wget https://github.com/Kitware/CMake/releases/download/v3.22.3/cmake-3.22.3.tar.gz

Extract your downloaded file:

tar -zxvf cmake-3.22.3.tar.gz

Now switch to your CMake directory:

cd cmake-3.22.3

Bootstrap Script

At this point, you need to Bootstrap the script. Be sure to install the dependencies mentioned above.

sudo ./bootstrap

This will take some time to complete.

After that build your package with the following command:

sudo make

Install CMake Latest Version on Ubuntu 20.04

Here you can install CMake with the following command:

sudo make install

This command will also take some minutes to complete.

When your installation is completed, you can verify your CMake installation by checking its version:

cmake --version
Output
cmake version 3.22.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).

Conclusion

At this point, you learn to Install CMake on Ubuntu 20.04.

Hope you enjoy it.

May this article is useful for you:

Install and Use CMake on Centos 7

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!