How to Install CMake on Ubuntu 22.04 LTS

CMake is an open-source, cross-platform family of tools designed to build, test, and package software. CMake is used to control the software compilation process using simple platform and compiler-independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice. Kitware created the suite of CMake tools in response to the need for a powerful, cross-platform build environment for open-source projects such as ITK and VTK.

In this article, we will describe how you can install CMake to your Ubuntu both through the UI and the command line.

We have run the commands and procedures mentioned in this article on Ubuntu 22.04 and Ubuntu 20.04.

Install CMake through the Ubuntu UI

The latest version of CMake is available through the Snap Store. Here, we will explain how you can install it through the Ubuntu Software Manager.

Installation

For a person who does not want to open the Command Line much, installing software present in the Ubuntu repository through the UI is very simple. On your Ubuntu desktop Activities toolbar, click the Ubuntu Software icon.

Ubuntu software center

In the following view, click on the search icon and enter “CMake” in the search bar. The search results will display Cmake as follows:

Search for CMake

The first package listed in the search result is the one maintained by the Snap Store. From the Software Manager, click on the CMake entry to open the following view:

Install CMake

Click the Install button to begin the installation process. The following authentication dialog will display for you to provide your authentication details as only an authorized user can install software on Ubuntu.

Authenticate as admin

Enter your password and click the Authenticate button. After that, the installation process will begin, displaying a progress bar as follows.

Installation progress CMake will then be installed to your system and you will get the following message after a successful installation:

Launch CMake

Through the above dialog, you can choose to directly launch CMake and even Remove it immediately for whatever reason.

Note: The same version of the software can be installed through the command line using the following command:

$ sudo snap install cmake

Remove CMake

If you want to remove CMake that was installed using the above method, you can remove it from your system as follows:

Open the Ubuntu Software Manager and search for CMake. You will see the “Installed” status in the search entry. Click this entry and then click Remove from the following view:

Remove CMake

Then, the system will prompt you with an Authentication dialog. The software will be removed when you provide the password for the sudo user and click Authenticate on the dialog.

Install CMake through the Ubuntu Command Line

If you prefer the command line over the UI, here is the method you must follow to install the latest version of CMake. I also tried installing CMake through default Ubuntu repositories and PPA, but none of them gave me the latest version. The only workable method involves downloading the source code from the Official CMake website “https://cmake.org/download/”, compiling it, and then installing CMake through it.

Open the Ubuntu command line, the Terminal, either through the Ctrl+Alt+T shortcut or the Application launcher search.

Install build tools and libraries that CMake depends on:

$ sudo apt-get install build-essential libssl-dev

Go to the temp directory:

$ cd /tmp

Then, enter the following command to download the source code:

$ wget https://github.com/Kitware/CMake/releases/download/v3.20.0/cmake-3.20.0.tar.gz

Once the tar.gz file is downloaded, enter the following command to extract it:

$ tar -zxvf cmake-3.20.0.tar.gz

Then move to the extracted folder as follows:

$ cd cmake-3.20.0

Finally, run the following commands to compile and install CMake:

./bootstrap

CMake Bootstrapping process

The bootstrap process may take some time, do not interrupt it. When CMake has bootstrapped, you will get the following output:

Bootstrap process finished

You can now make it using the following command:

$ make

Building Cmake

And then install it as follows:

$ sudo make install

Make install of CMake

After the software is successfully installed, you can verify its installation and also if the correct version is installed, through the following command:

$ cmake --version

Cmake version

CMake 3.20.0 has been installed successfully on Ubuntu. You can now use the CLI tool to work with your software's code.