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.
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
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:
If you want to an environment-dependent way of changing the version of CMake, just updating your PATHseems 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.
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!
(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.
#!/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