Choose a different version or distribution
Introduction
Before we discuss how to install CMake on Ubuntu 22.04, let's first understand-What is CMake?
CMake is an open-source, cross-platform build system that helps developers manage the build process of software projects. Based on a basic, platform-independent configuration script, it creates build files that are specific to a given platform, like Makefiles or Visual Studio projects.
This tutorial will walk you through the process of installing CMake on Ubuntu 22.04.
Advantages
- Cross-Platform Compatibility: CMake works across different platforms, including Linux, Windows, macOS, and more. It provides a consistent build system that allows you to manage projects on various operating systems.
- Simplicity and Flexibility: CMake uses a simple and readable syntax to define build configurations. It offers flexible options for customizing the build process, making it suitable for small projects as well as large-scale applications.
- Support for Various Build Systems: CMake supports a wide range of build systems, such as Make, Ninja, and Visual Studio. This allows developers to choose the most suitable build system for their project or platform.
- Dependency Management: CMake simplifies dependency management by providing mechanisms for finding, including, and linking external libraries or packages. It helps automate the process of locating and integrating dependencies into the build system.
- Modularity and Hierarchical Structure: CMake supports modular and hierarchical project structures. It enables developers to organize their codebase into separate modules or libraries, facilitating better code organization and reusability.
Methods to Install CMake on Ubuntu 22.04
Method 1: Using Snap Store
CMake is available via the snap store on a number of Linux systems. To manage these snaps, utilize the snapcraft tool. On Ubuntu 22.04, snap support is pre-installed.
Simply run the command listed below to install CMake.
sudo snap install cmake --classic
Use the command to show the version of the CMake package to verify that it has been installed.:
cmake --version
Remove CMake Using CLI
The package can be quickly uninstalled from the system using the following methods if it was installed through the Snap Store:
sudo snap remove cmake
The package will be removed.
Method 2: Using Ubuntu Software
To install CMake on Ubuntu 22.04, utilize the Ubuntu software program. Let's examine how to install it:
To access the Ubuntu application store, type "ubuntu software" into the "Applications" search box and select the icon:
When the Ubuntu software program launches, type "cmake" to find the CMake package:
![Search CMake](https://vegastack.com/tutorials/content/images/2024/06/cmake-appstore.png)
After selecting the CMake package, click the "Install" button:
![Click on Install](https://vegastack.com/tutorials/content/images/2024/01/image-40.png)
In order to move on to the next step, enter the password when prompted for authentication purposes.
Once the installation is finished, type "cmake" into the Applications search bar:
![Launch Cmake](https://vegastack.com/tutorials/content/images/2024/01/image-41.png)
When you click on the icon, the CMake application opens:
![UI of Cmake](https://vegastack.com/tutorials/content/images/2024/01/image-42.png)
Remove CMake Using GUI
Navigate to the "Ubuntu Software Center" to uninstall it:
Look for "cmake" and then click the "Installed" version:
![Click on trash icon](https://vegastack.com/tutorials/content/images/2024/01/image-43.png)
A new pop-up will appear to confirm the uninstallation; click on “Uninstall”:
![Click on Uninstall](https://vegastack.com/tutorials/content/images/2024/01/image-44.png)
The password for "sudo" will be requested; enter it and click "Authenticate". The "CMake" will then be deleted from the system following a successful authentication.
Method 3: Using GitHub
A list of packages is available for users to install on GitHub. The following steps can be used to install CMake from GitHub using this method:
Step 1: Install the dependencies
Installing the dependencies needed to handle the source files from GitHub should come first:
sudo apt install build-essential libssl-dev
Step 2: Download the tar file of CMake
Next, use the following command to obtain the CMake package from GitHub:
wget -c https://github.com/Kitware/CMake/releases/download/v3.20.1/cmake-3.20.1.tar.gz
Step 3: Extract the Downloaded tar file
After downloading the package, use the following command to extract its files:
tar -zxvf cmake-3.20.1.tar.gz
Navigate to the extracted folder by using the command:
cd cmake-3.20.1
Step 4: Run the Bootstrap Script
Run the following command to compile the package after it has been executed:
sudo ./bootstrap
Step 5: Build the Package
It will take some time, so after the command has finished running, run the following command:
sudo make
Step 6: Install CMake
Once every package has been built, execute the CMake installation command:
sudo make install
Display the version using the following command to verify the installation:
cmake --version
FAQs to Install CMake on Ubuntu 22.04
Can I install a specific version of CMake on Ubuntu 22.04?
By default, Ubuntu 22.04 provides the latest version of CMake available in its package repository. However, you can install a specific version by following the instructions provided by the CMake project or by building it from source.
How do I check the installed version of CMake on Ubuntu 22.04?
Open a terminal and run the command: cmake --version
. It will display the installed version of CMake.
Can I use CMake for projects written in different programming languages?
Yes, CMake is designed to work with projects written in various programming languages, including C, C++, Python, Java, and more.
How do I create a CMake build configuration for my project?
In the root directory of your project, create a CMakeLists.txt
file and define the project configuration using CMake syntax. Refer to the CMake documentation for more details and examples.
Can I generate a specific build system using CMake?
Yes, CMake can generate build system files for various platforms and build tools, such as Makefiles (for Make), Visual Studio solution files, Xcode projects, and more.
How do I compile and build my project using CMake on Ubuntu 22.04?
Create a separate directory (e.g., build/
) within your project's root directory, navigate to that directory in a terminal, run cmake ..
to generate build files, and then run make
to compile and build the project.
Can I include external libraries or packages in my CMake project?
Yes, CMake provides mechanisms to include and link external libraries or packages. You can use commands like find_package
or target_link_libraries
to manage dependencies.
Conclusion
There are three ways to install the CMake package; on Ubuntu 22.04, the easiest way is to use the command sudo snap install cmake –classic.
Three distinct CMake installation methods have been covered in this tutorial. Because CMake is accessible through the Ubuntu default repository and the snap store, Ubuntu 22.04's CLI and GUI can be used to install it. Additionally, CMake source packages from GitHub can be used to install it on Ubuntu 22.04.
If you have any queries, you can ask them in the comments section, and we would be happy to answer them...