[ubuntu]cmake安装的3种方法

第一种:apt安装

sudo apt-get install cmake

这个安装一般不是最新的,安装最新的需要ppa安装这里以ubuntu18.04为例子:

添加签名密钥

wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add -
将存储库添加到您的源列表并进行更新

稳定版

sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'
sudo apt-get update

候选发布版本
sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic-rc main'
sudo apt-get update


查看版本:cmake --version

第二种:源码安装

1.下载源码包

        官网下载地址:Download | CMake

        选择最新版本的源码包:cmake-xxxxxx.tar.gz

 2.安装工具

        需要安装gcc、g++、make

sudo apt-get install gcc

sudo apt-get install g++

sudo apt-get install make

 3.安装源码包

       根据安装版本修改文件名, 解压压缩包:

tar -zxvf cmake-3.21.2.tar.gz
        进入解压后的文件目录下,执行如下命令
./configure

make
make install

4.检查是否安装成功

cmake -version
第三种:sh安装

下载指定版本的sh文件

https://cmake.org/files/

安装指令:sudo bash xxxxxx.sh