The correct way to upgrade Cmake in Ubuntu

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:

  1. 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
    
  2. Unzip:

    tar -xvzf cmake-3.22.1.tar.gz
    
  3. Enter the decompression directory, after the configuration is successful, it will display:CMake has bootstrapped. Now run make.

    chmod 777 ./configure
    ./configure
    
  4. After the configuration is complete, compile:

    make
    
  5. After compiling, install:

    sudo make install
    
  6. Finally, replace the old version with the newly installed cmake, where is /usr/local/bin/cmakethe newly installed cmake directory.

    sudo update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force
    
  7. Finally test the cmake version:

    cmake --version
    # cmake version 3.22.1
    
    # CMake suite maintained and supported by Kitware (kitware.com/cmake).
    
  8. principle

    Before installation:
    insert image description here
    After installation:
    insert image description here

    You can see /usr/binthat 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-alternativesdetails, please refer to:

    [1] https://blog.csdn.net/JasonDing1354/article/details/50470109

    [2] https://www.jianshu.com/p/08d08713f0d1

Guess you like

Origin blog.csdn.net/qq_27350133/article/details/121994229