How To Install cmake on Ubuntu 22.04
In this guide, we’ll discuss How To Install cmake on Ubuntu 22.04.
Also, we will demonstrate how to uninstall and update
cmake
.
One-liner install command
For those in a hurry, here's a one-line installation command:
sudo apt-get update && sudo apt -y install cmake
But if you are interested in the detailed steps with descriptions, the following information is for you.
What is cmake
and what are
the ways to install it?
Short description: Cross-platform build system generator. It generates Makefiles, Visual Studio projects or others, depending on the target system.
Before beginning this tutorial, you will need access to a server or computer running Ubuntu 22.04. This guide was written specifically with a server running Ubuntu 22.04 in mind, although it should also work on older, supported versions of the operating system.
Also, make sure you are running a regular, non-root user with sudo privileges configured on your server. When you have an account available, log in as your non-root user to begin.
There are several ways to install cmake on Ubuntu 22.04. You can use (links are clickable):
In the following sections, we will describe each method in detail. You can choose one of them or refer to the recommended one.
Install cmake using apt-get
First, update apt database with apt-get
using the following command.
sudo apt-get update
After updating apt-get
database,
You can install cmake using apt
by running the
following command:
sudo apt -y install cmake
Install cmake using apt
Because cmake is available in Ubuntu 22.04’s default repositories, it is possible to install it from these repositories using the apt packaging system.
To begin, update apt database with apt
using the following command.
sudo apt update
After updating apt
database,
You can install cmake using apt
by running the
following command:
sudo apt -y install cmake
Install cmake using aptitude
If you want to follow this method, you might need to install aptitude first since aptitude is usually not installed by default on Ubuntu 22.04. Update apt database with aptitude using the following command.
sudo aptitude update
After updating aptitude
database,
You can install cmake by running the following command:
sudo aptitude -y install cmake
How to upgrade (update) a single package cmake using apt-get?
First, you will need to update packages index. Run update
command as
usual:
sudo apt-get update
Next, to upgrade only the cmake, e.g. single package, you should use the following format with the apt-get command/apt command:
sudo apt-get --only-upgrade install cmake
Note that this command will not install any new packages! If you wish to install the
package if it doesn't exist you may leave out --only-upgrade
part.
It's Good to Know:
sudo apt-get install cmake
This will upgrade the package even if is already installed.
How To Uninstall cmake from Ubuntu 22.04
To uninstall only the cmake
package you can execute
the
following command:
sudo apt-get remove cmake
Uninstall cmake and all its dependencies
To uninstall cmake and its dependencies that are no longer needed by Ubuntu 22.04, you can use the command below:
sudo apt-get -y autoremove cmake
Remove cmake with all configurations and data
To remove cmake configuration and data
from your system you can run the following purge
command:
sudo apt-get -y purge cmake
Remove cmake completely (configurations, data and all of its dependencies)
And lastly, you can run the next command to remove absolutely everything related to cmake package, e.g.: configurations, data and all of its dependencies. Just use this command:
sudo apt-get -y autoremove --purge cmake
Extra info and code examples
-
Generate a Makefile and use it to compile a project in the same folder as the source:
cmake && make
-
Generate a Makefile and use it to compile a project in a separate "build" folder (out-of-source build):
cmake -H. -Bbuild && make -C build
-
Run cmake in interactive mode (it will ask for each variable, instead of using defaults):
cmake -i
- Maintainer: Debian CMake Team
- Sources url: https://cmake.org/
- Section/Category: devel
Conclusion
You now have a full guide on how to install cmake
using apt, apt-get and aptitude tools.
Also, we showed how to update as a single package and different ways to uninstall
the cmake from Ubuntu 22.04.