Ubuntu 20.04通过apt安装的cmake版本是3.16.3,默认安装到/usr/bin/cmake路径。
$ cmake Command 'cmake' not found, but can be installed with:sudo snap install cmake # version 3.29.3, or
sudo apt install cmake # version 3.16.3-1ubuntu1.20.04.1See 'snap info cmake' for additional versions.
如果想安装其他版本,比如v3.22.6,可以到cmake的历史版本网页中下载。
Index of /files/v3.22https://cmake.org/files/v3.22/下载路径:
https://cmake.org/files/v3.22/cmake-3.22.6-linux-x86_64.shhttps://cmake.org/files/v3.22/cmake-3.22.6-linux-x86_64.sh
下面是在Ubuntu上的安装过程
# 创建目录
$ sudo mkdir /opt/cmake# 下载文件
$ cd /opt/cmake
$ sudo wget https://cmake.org/files/v3.22/cmake-3.22.6-linux-x86_64.sh
$ sudo chmod +x cmake-3.22.6-linux-x86_64.sh# 安装程序,期间要回复确认
$ sudo ./cmake-3.22.6-linux-x86_64.sh# 创建软连接
$ cd /usr/bin
$ sudo ln -s /opt/cmake/cmake-3.22.6-linux-x86_64/bin/cmake cmake
安装完成后,即可在任意路径执行cmake
~$ cmake
Usagecmake [options] <path-to-source>cmake [options] <path-to-existing-build>cmake [options] -S <path-to-source> -B <path-to-build>Specify a source directory to (re-)generate a build system for it in the
current working directory. Specify an existing build directory to
re-generate its build system.Run 'cmake --help' for more information.