Installing CMake#
Tip
Your CMake version should be newer than your compiler. It should be newer than the libraries you are using. New versions work better for everyone.
If you have a built in copy of CMake, it isn’t special or customized for your system. You can easily install a new one instead, either on the system level or the user level. Feel free to instruct your users here if they complain about a CMake requirement being set too high. Especially if they want 3.15+ support. Maybe even if they want 3.31+ support…
Quick list (more info on each method below)#
Ordered by author preference:
All
Pip(x) (official, often updates same-day)
Windows
Download binary (official)
MacOS
Download binary (official)
Linux
Snapcraft (official)
APT repository (Ubuntu/Debian only) (official)
Download binary (official)
Official package#
You can download CMake from KitWare. This is how you will probably get CMake if you are on Windows. It’s not a bad way to get it on macOS either (and a Universal2 version is supplied supporting both Intel and Apple Silicon), but using brew install cmake
is much nicer if you use Homebrew (and you should; Apple even supports Homebrew such as during the Apple Silicon rollout). You can also get it on most other package managers, such as Chocolatey for Windows or MacPorts for macOS.
On Linux, there are several options. Kitware provides a Debian/Ubuntu apt repository, as well as snap packages. There are universal Linux binaries provided, but you’ll need to pick an install location. If you already use ~/.local
for user-space packages, the following single line command[1] will get CMake for you [2]:
~ $ wget -qO- "https://cmake.org/files/v3.31/cmake-3.31.0-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C ~/.local
The names changed in 3.20; older releases had names like cmake-3.19.7-Linux-x86_64.tar.gz
. If you just want a local folder with CMake only:
~ $ mkdir -p cmake-3.31 && wget -qO- "https://cmake.org/files/v3.31/cmake-3.31.0-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C cmake-3.31
~ $ export PATH=`pwd`/cmake-3.31/bin:$PATH
You’ll obviously want to append to the PATH every time you start a new terminal, or add it to your .bashrc
or to an LMod system.
And, if you want a system install, install to /usr/local
; this is an excellent choice in a Docker container, for example on GitLab CI. Do not try it on a non-containerized system.
docker $ wget -qO- "https://cmake.org/files/v3.31/cmake-3.31.0-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local
If you are on a system without wget, replace wget -qO-
with curl -s
.
You can also build CMake on any system, it’s pretty easy, but binaries are faster.
CMake Default Versions#
Here are some common build environments and the CMake version you’ll find on them. Feel free to install CMake yourself, it’s 1-2 lines and there’s nothing “special” about the built in version. It’s also very backward compatible.
Windows#
The winget package is a good way to get CMake. Other options:
Also Scoop is generally up to date. The normal installers from CMake.org are common on Windows, too.
MacOS#
Homebrew is quite a bit more popular nowadays on macOS, at least according to Google Trends.
Linux#
RHEL/CentOS#
The default on 8 is not too bad, but you should not use the default on the end-of-life CentOS 7. Use the EPEL package instead.
Ubuntu#
Debian#
Other#
General tools#
Just pip install cmake
on many systems. Add --user
if you have to (modern pip does this for you if needed). This does not supply Universal2 wheels yet.
CI#
Distribution |
CMake version |
Notes |
---|---|---|
3.31.0 |
kept up to date |
|
3.31.0 |
Same runners as Azure DevOps |
If you are using GitHub Actions, also see the jwlawson/actions-setup-cmake action, which can install your selection of CMake, even in a docker action run.
Full list#
Versions less than 3.15 are marked by a deeper color of red.
Also see pkgs.org/download/cmake.
Pip#
This is also provided as an official package, maintained by the authors of CMake at KitWare and several PyPA members, including myself. It’s now supported on special architectures, like PowerPC on Linux and Apple Silicon on macOS, and on MUSL systems like Alpine too. If you have pip (Python’s package installer), you can do:
pip install cmake
And as long as a binary exists for your system, you’ll be up-and-running almost immediately. If a binary doesn’t exist, it will try to use KitWare’s scikit-build
package to build, and will require an older copy of CMake to build. So only use this system if binaries exist, which is most of the time.
This has the benefit of respecting your current virtual environment, as well. It really shines when placed in a pyproject.toml
file, however - it will only be installed to build your package, and will not remain afterwards! Fantastic.
This also, of course, works with pipx. So you can even use pipx run cmake
to run CMake in a disposable virtual environment, without any setup - and this works out-of-the-box on GitHub Actions, since pipx
is a supported package manager there!
Tip
Personally, on Linux, I put versions of CMake in folders, like /opt/cmake312
or ~/opt/cmake312
, and then add them to LMod. See envmodule_setup
for help setting up an LMod system on macOS or Linux. It takes a bit to learn, but is a great way to manage package and compiler versions.