CMake is an open-source, cross-platform family of tools for building, testing, and packaging software. CMake is used to control the process of compiling software using simple configuration files that are independent of the platform and the compiler, as well as to create your own makefiles and workspaces that you can use in your compiler environment. Kitware created the CMake toolkit 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 on Ubuntu both through the user interface and from the command line.
We ran the commands and procedures mentioned in this article on the Ubuntu 18.04 LTS system.
Install CMake via Ubuntu UI
At the time of this writing, the latest version of CMake was 3.15.2 and, fortunately, is available through the Snap Store. Here we explain how you can install it through Ubuntu Software Manager.
For a person who does not want to open the command line much, installing the software present in the Ubuntu repository through the user interface is very simple. On the Actions toolbar on the Ubuntu desktop, click the Ubuntu Software icon.
In the next window, click on the search icon and enter “CMake” in the search bar. Search results will display Cmake as follows:
The first package listed in the search results is a package supported by the Snap Store. In the software manager, click the CMake entry to open the following view:
Click the Install button to start the installation process. The next authentication dialog will show you the opportunity to provide your authentication information, since only an authorized user can install the software in Ubuntu
Enter your password and click the Authentication button. After that, the installation process will begin, displaying a progress bar as follows.
Then CMake will be installed on your system, and after successful installation you will receive the following message:
In the above dialog box, you can directly launch CMake and even remove it immediately for any reason.
Remarks: The same software version can be installed via the command line using the following command:
$ sudo snap install cmake
If you want to remove CMake, which was installed in the above way, you can remove it from your system as follows:
Open Ubuntu Software Manager and find CMake. You will see the “Installed” status in the search bar. Click this entry, and then click Delete from the following view:
Then the system will offer you an authentication dialog. The software will be removed when you provide the password for the sudo user and click the “Authentication” button in the dialog box.
Install CMake via Ubuntu Command Prompt
If you prefer the command line rather than the user interface, here is the method you will need to follow to install the latest version of CMake. I also tried installing CMake through standard Ubuntu repositories as well as through PPA, but none of them gave me the latest version. The only working 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, Terminal or through Ctrl + Alt + T shortcut or through the search application launcher.
Then enter the following command to download the source code:
$ wget https://github.com/Kitware/CMake/releases/download/v3.15.2/cmake-3.15.2.tar.gz
After loading the tar.gz file, enter the following command to extract it:
$ tar -zxvf cmake-3.15.2.tar.gz
Then navigate to the extracted folder as follows:
$ cd cmake-3.15.2
Finally, run the following commands to compile and install CMake:
When CMake boots up, you get the following output:
Now you can do this with the following command:
And then install it as follows:
$ sudo make install
After successfully installing the software, you can verify its installation, and also, if the correct version is installed, using the following command:
$ cmake --version
You can see that CMake 1.15.2, which was the latest software at the time of this writing, is installed on my Ubuntu. Now you can use the CLI tool to work with your software code.
How to install CMake on Ubuntu 18.04 LTS