# Ubuntu: installing multiple CMake versions

**URL:** https://discourse.cmake.org/t/ubuntu-installing-multiple-cmake-versions/15402
**Category:** Usage
**Created:** [December 15, 2025, 3:46pm UTC](https://discourse.cmake.org/t/ubuntu-installing-multiple-cmake-versions/15402 "2025-12-15T15:46:05Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [December 15, 2025, 3:46pm UTC](https://discourse.cmake.org/t/ubuntu-installing-multiple-cmake-versions/15402/1 "2025-12-15T15:46:05Z")

</div>

This is related to: [Windows: how to have multiple CMake versions installed?](https://discourse.cmake.org/t/windows-how-to-have-multiple-cmake-versions-installed/1491)

In my case, I’d like to use `update-alternatives` to switch between versions.  
The default one was installed through `sudo apt install cmake` which installed it into `/usr/bin`. The version si 3.28.

I extracted an older version from [https://cmake.org/files/v3.20/](https://cmake.org/files/v3.20/) into `~/somepath/`.

Now I can’t find the right way to use `update-alternatives`.

`sudo update-alternatives /usr/bin/cmake cmake /usr/bin/cmake 100` fails because the link and path arguments are the same.

I found many suggestions on the web that implies to rename or move `/usr/bin/cmake` which might breaks things with respect to `apt` or if I call later `sudo update-alternatives --remove-all cmake`

Regards  
A.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [December 15, 2025, 7:16pm UTC](https://discourse.cmake.org/t/ubuntu-installing-multiple-cmake-versions/15402/2 "2025-12-15T19:16:36Z")

</div>

I would use

> pipx install cmake==3.20

In general, you may use pipx or venv and install many useful tools like:

```auto
# PyPi
isort>=7.0.0
black>=25.11
cmake>=3.25
gcovr>=8.4
ninja>=1.13
yamllint>=1.37
builddriver>=0.9
bumpversion>=0.6.0
codespell>=2.4.1
clang-tidy==21.1.1
clang-format==21.1.6
gersemi>=0.23.2
pre-commit>=4.5.0
pylint
pytest>=9.0.1
pip-tools

```

---

<div class="post-metadata">

### Author: ![AnthonyD973](https://discourse.cmake.org/user_avatar/discourse.cmake.org/anthonyd973/32/3130_2.png) [@AnthonyD973](https://discourse.cmake.org/u/AnthonyD973)
#### Post date: [December 16, 2025, 4:53am UTC](https://discourse.cmake.org/t/ubuntu-installing-multiple-cmake-versions/15402/3 "2025-12-16T04:53:03Z")

</div>

> [@adaldev](#):
>
> I found many suggestions on the web that implies to rename or move `/usr/bin/cmake` which might breaks things with respect to `apt`

Yeah, I definitely wouldn’t mess with the package manager’s stuff!

Not _quite_ a direct answer, but rather than `update-alternatives` I’d suggest one of these solutions:

1. If you want to an environment-dependent way of changing the version of CMake, just updating your `PATH`seems like a better solution. I don’t often use `update-alternatives`, but I suppose if you switch the version of the `cmake` executable, the version of the other tools (ctest, cpack, etc.) wouldn’t change. At this point, for robustness and consistency, just change the `PATH`.
2. If you need consistency across multiple machines (e.g. CI builds, or in a company-owned developer machine scenario), I’d instead suggess specifying the full path to cmake, e.g. `/home/me/devtool/cmake/bin/cmake`, perhaps making that path configurable in some project-dependent way (e.g. a default that is overridable by a flag to the overarching build or something like that). How that version of CMake gets installed and where is up to you!
3. (EDIT: This option is more if you wanted a more recent version than the package manager gives you). If you don’t need/want to care about the version of CMake, then you could accept lagging behind. In that case, choose a minimum version you want to support for now, don’t rely on features newer than that, and specify that version in your `cmake_minimum_required`.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [December 16, 2025, 6:14am UTC](https://discourse.cmake.org/t/ubuntu-installing-multiple-cmake-versions/15402/4 "2025-12-16T06:14:29Z")

</div>

This script works for me i.e.

```bash
#!/bin/sh
set -e
set -u
set -x

cd ${HOME}/.local/bin

for f in gcov gcc g++ gcc-nm gcc-ranlib gcc-ar; do
    sudo update-alternatives --install ${PWD}/${f} ${f} /usr/bin/${f}-13 10
done

```
