The correct way to upgrade Cmake in Ubuntu
Some software packages require a higher version of Cmake when compiling, so Cmake needs to be upgraded. You cannot use
sudo apt-get remove cmake
Uninstall the lower version of cmake and then reinstall the higher version. Doing so will cause many libraries compiled and installed before to be uninstalled together! ! !
The correct steps are:
-
Go to https://cmake.org/files/ to download the source code of the required version. You can also use wget to download, for example:
wget https://cmake.org/files/v3.22/cmake-3.22.1.tar.gz
-
Unzip:
tar -xvzf cmake-3.22.1.tar.gz
-
Enter the decompression directory, after the configuration is successful, it will display:
CMake has bootstrapped. Now run make.
chmod 777 ./configure ./configure
-
After the configuration is complete, compile:
make
-
After compiling, install:
sudo make install
-
Finally, replace the old version with the newly installed cmake, where is
/usr/local/bin/cmake
the newly installed cmake directory.sudo update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force
-
Finally test the cmake version:
cmake --version # cmake version 3.22.1 # CMake suite maintained and supported by Kitware (kitware.com/cmake).
-
principle
Before installation:
After installation:
You can see
/usr/bin
that the cmake in the directory has become a soft link, pointing to/etc/alternatives/cmake
, and the latter is pointing to/usr/local/bin/cmake
, which is the version we installed. In fact, the original program is "replaced" by means of soft links.For
update-alternatives
details, please refer to:[1] https://blog.csdn.net/JasonDing1354/article/details/50470109