Ubuntu20.04升级cmake(不用去额外删除现有版本)

描述

Ubuntu20.04安装cmake,并灵活更改cmake版本。

安装命令

sudo apt-get install cmake

cmake版本不符时

部分工程可能对cmake版本做出了要求,一般来说在CMakeLists.txt中的第一句话会有这样的设定。括号内就是编译使用的cmake最小版本号

cmake_minimum_required(VERSION 3.20)

如果版本不符,会有如下提示

CMake 3.20 or higher is required.  You are running version 3.16.3

当前我们的版本是3.16.3,而这个工程需要3.20以上。这时我们需要升级我们的cmake

升级版本

打开cmake下载的官网:https://cmake.org/files/

这里我们选择最高的子版本,cmake-3.20.6-linux-x86_64.sh,点击进行下载。(最小的子版本号可以自行更改,我选的是当时最高的6,因为它大概率拥有最全的补丁)

升级命令

cd Downloads
sudo bash cmake-3.20.6-inux-x86_64.sh --skip-licence --prefix=/usr

在弹出来的提示中,输入y/n(输入什么完全照我说的做!)

# 安装过程中遇到:
# 第一个选择时,输入y!!!
Do you accept the license? [yn]: 
# 输入 y

# 第二个选择时,输入n!!!
By default the CMake will be installed in:
  "/usr/cmake-3.23.0-linux-x86_64"
Do you want to include the subdirectory cmake-3.23.0-linux-x86_64?
Saying no will install in: "/usr" [Yn]:
# 输入 n

这时会自动安装了

查看cmake版本

升级后,可以确认cmake版本

cmake --version

提示

cmake version 3.20.6

成功

猜你喜欢

转载自blog.csdn.net/weixin_42156097/article/details/126932003