This guide installs CMake on a Linux host.
sudo apt update
sudo apt install -y cmake build-essential
sudo dnf install -y cmake gcc gcc-c++ make
For newer CMake versions than distro packages provide, use Kitware’s APT repository:
# Install prerequisites
sudo apt update
sudo apt install -y apt-transport-https ca-certificates gnupg curl
# Add Kitware GPG key
curl -fsSL https://apt.kitware.com/keys/kitware-archive-latest.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/kitware.gpg
# Add repository (adjust codename for your Ubuntu version)
sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ jammy main'
# Install CMake
sudo apt update
sudo apt install -y cmake
# Check version
cmake --version
# Should output something like: cmake version 3.22.1
Create a user CMake presets file ~/.cmake/presets.json:
{
"version": 3,
"configurePresets": [
{
"name": "default",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
]
}
See CMake Configuration for configuration guidance.
See CMake Security for hardening guidance.
Need professional assistance with your build infrastructure? Our team provides:
Get in touch: office@linux-server-admin.com | Contact Page
References: