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.