Table of Contents
In this article, I will take you through the steps to install cmake on Ubuntu 22.04 LTS. cmake is a free and open source tool designed to build, test and package software. It controls the compilation of the programs by using compiler independent configuration files. cmake look for a script file called CMakeLists.txt to generate build files natively. Hence it relies on lot of variables to be set before you can actually use it to generate build files. This also gives you the flexibility to use the compiler of your choice.
The suite of cmake tools were created by Kitware due to a requirement for a powerful, cross-platform build environment for open-source projects such as ITK and VTK. It is also easy to install and use in Linux based platforms. Here we will see the steps to install cmake on Ubuntu 22.04 LTS based systems.
How to Install cmake on Ubuntu 22.04 LTS (Jammy Jellyfish)
Also Read: How to Install Atlassian Command Line Interface(CLI) on Linux
Step 1: Prerequisites
a) You should have a running Ubuntu 22.04 LTS
Server.
b) You should have sudo
or root
access to run privileged commands.
c) You should have apt
or snap
installed in your System.
Step 2: Update Your Server
First you need to check for all the available updates and then install it by using sudo apt update && sudo apt upgrade
command as shown below.
cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade [sudo] password for cyberithub: Hit:1 http://in.archive.ubuntu.com/ubuntu jammy InRelease Hit:2 http://security.ubuntu.com/ubuntu jammy-security InRelease Hit:3 https://artifacts.elastic.co/packages/8.x/apt stable InRelease Hit:4 http://in.archive.ubuntu.com/ubuntu jammy-updates InRelease Hit:5 https://dl.google.com/linux/chrome/deb stable InRelease Hit:6 http://in.archive.ubuntu.com/ubuntu jammy-backports InRelease Reading package lists... Done Building dependency tree... Done Reading state information... Done 35 packages can be upgraded. Run 'apt list --upgradable' to see them. Reading package lists... Done Building dependency tree... Done Reading state information... Done Calculating upgrade... Done # # An OpenSSL vulnerability has recently been fixed with USN-6188-1 & 6119-1: # CVE-2023-2650: possible DoS translating ASN.1 object identifiers. # Ensure you have updated the package to its latest version. # The following NEW packages will be installed: firefox The following packages have been kept back: gjs libgjs0g The following packages will be upgraded: alsa-ucm-conf gir1.2-adw-1 gir1.2-gnomedesktop-3.0 gir1.2-mutter-10 gnome-desktop3-data gnome-shell gnome-shell-common initramfs-tools initramfs-tools-bin initramfs-tools-core libadwaita-1-0 libgnome-bg-4-1 libgnome-desktop-3-19 libgnome-desktop-4-1 libidn12 libinput-bin libinput10 libmm-glib0 libmutter-10-0 libspeechd2 modemmanager mutter-common python3-debian python3-speechd speech-dispatcher speech-dispatcher-audio-plugins speech-dispatcher-espeak-ng ubuntu-advantage-tools ubuntu-desktop ubuntu-desktop-minimal ubuntu-drivers-common ubuntu-minimal ubuntu-standard 33 upgraded, 1 newly installed, 0 to remove and 2 not upgraded. Need to get 9,001 kB of archives. After this operation, 375 kB of additional disk space will be used. Do you want to continue? [Y/n] Y ......................................................................
Step 3: Install cmake
In the next step, you can install cmake by using any of the below method depending on your requirement and tools availability.
a) Using APT
If you are looking to install cmake from default Ubuntu repo then you need to run sudo apt install cmake
command as shown below. This will download and install the package along with all its dependencies.
cyberithub@ubuntu:~$ sudo apt install cmake [sudo] password for cyberithub: Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: binutils binutils-common binutils-x86-64-linux-gnu cmake-data dh-elpa-helper gcc gcc-11 libasan6 libbinutils libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libgcc-11-dev libitm1 libjsoncpp25 liblsan0 libnsl-dev libquadmath0 librhash0 libtirpc-dev libtsan0 libubsan1 linux-libc-dev make manpages-dev rpcsvc-proto Suggested packages: binutils-doc cmake-doc ninja-build cmake-format gcc-multilib autoconf automake libtool flex bison gcc-doc gcc-11-multilib gcc-11-doc gcc-11-locales glibc-doc make-doc The following NEW packages will be installed: binutils binutils-common binutils-x86-64-linux-gnu cmake cmake-data dh-elpa-helper gcc gcc-11 libasan6 libbinutils libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libgcc-11-dev libitm1 libjsoncpp25 liblsan0 libnsl-dev libquadmath0 librhash0 libtirpc-dev libtsan0 libubsan1 linux-libc-dev make manpages-dev rpcsvc-proto 0 upgraded, 31 newly installed, 0 to remove and 2 not upgraded. Need to get 46.4 MB of archives. After this operation, 163 MB of additional disk space will be used. Do you want to continue? [Y/n] Y ..................................................................
b) Using Snap
If you are looking to install cmake as a snap package from Snap store then you need to use use sudo snap install cmake --classic
command as shown below.
cyberithub@ubuntu:~$ sudo snap install cmake --classic cmake 3.26.4 from Crascit** installed
Step 4: Verify Installation
After successful installation, you can verify the installed files path by using dpkg -L cmake
command as shown below.
cyberithub@ubuntu:~$ dpkg -L cmake
/.
/usr
/usr/bin
/usr/bin/cmake
/usr/bin/cpack
/usr/bin/ctest
/usr/share
/usr/share/bash-completion
/usr/share/bash-completion/completions
/usr/share/bash-completion/completions/cmake
/usr/share/bash-completion/completions/cpack
/usr/share/bash-completion/completions/ctest
/usr/share/cmake
/usr/share/cmake/debtoolchainfilegen
/usr/share/doc
/usr/share/doc/cmake
/usr/share/doc/cmake/NEWS.Debian.gz
/usr/share/doc/cmake/changelog.Debian.gz
/usr/share/doc/cmake/copyright
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/cmake
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/cmake.1.gz
/usr/share/man/man1/cpack.1.gz
/usr/share/man/man1/ctest.1.gz
Step 5: Check Version
You can check the current installed version by using cmake --version
command as shown below.
cyberithub@ubuntu:~$ cmake --version cmake version 3.26.4 CMake suite maintained and supported by Kitware (kitware.com/cmake).
Step 6: Using cmake
Now that cmake is installed, let's create CMakeLists.txt
in source directory /home/cyberithub
with below contents in it to test the tool.
cyberithub@ubuntu:~$ nano CMakeLists.txt cmake_minimum_required (VERSION 2.8.11) project (HELLO) add_subdirectory (Hello)
Then create a subdirectory called Hello
using mkdir Hello
command and switch to it using cd Hello
command as shown below.
cyberithub@ubuntu:~$ mkdir Hello cyberithub@ubuntu:~$ cd Hello/
Now run cmake ../
command to check if the cmake tool is working fine. As you can see from below output, cmake detected the CMakeLists.txt
file and building the configuration. This confirms that cmake is working as expected and now you can proceed with your work.
cyberithub@ubuntu:~/Hello$ cmake ../
CMake Deprecation Warning at CMakeLists.txt:4 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
.................................................
Step 7: Uninstall cmake
Once you are done with cmake, you can choose to uninstall it from your system by using any of the below methods depending on how you have installed.
a) Using APT
If you installed from default Ubuntu repo then to remove the package you need to use sudo apt remove cmake
command as shown below. However, you need to be very careful before removing the package as it is possible that some other running application might be actively using it.
cyberithub@ubuntu:~$ sudo apt remove cmake Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages were automatically installed and are no longer required: cmake-data dh-elpa-helper gcc gcc-11 libasan6 libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev libgcc-11-dev libitm1 libjsoncpp25 liblsan0 libnsl-dev libquadmath0 librhash0 libtirpc-dev libtsan0 libubsan1 linux-libc-dev manpages-dev rpcsvc-proto Use 'sudo apt autoremove' to remove them. The following packages will be REMOVED: cmake 0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded. After this operation, 21.2 MB disk space will be freed. Do you want to continue? [Y/n] Y (Reading database ... 229079 files and directories currently installed.) Removing cmake (3.22.1-1ubuntu1.22.04.1) ... Processing triggers for man-db (2.10.2-1) ...
b) Using Snap
If you installed cmake as snap package then you need to run sudo snap remove cmake
command to uninstall the package from your System.
cyberithub@ubuntu:~$ sudo snap remove cmake cmake removed