以下方法二选一

源码编译

下载源码

wget https://cmake.org/files/v3.12/cmake-3.12.3.tar.gz

编译安装

tar zxvf cmake-3.*
cd cmake-3.*
./bootstrap --prefix=/usr/local
make -j$(nproc)
make install

验证版本

cmake --version

cmake version *.*.*
CMake suite maintained and supported by Kitware (kitware.com/cmake).

yum安装

添加仓库

echo '[group_kdesig-cmake3_EPEL]
name=Copr repo for cmake3_EPEL owned by @kdesig
baseurl=https://copr-be.cloud.fedoraproject.org/results/@kdesig/cmake3_EPEL/epel-7-$basearch/
type=rpm-md
skip_if_unavailable=True
gpgcheck=1
gpgkey=https://copr-be.cloud.fedoraproject.org/results/@kdesig/cmake3_EPEL/pubkey.gpg
repo_gpgcheck=0
enabled=1
enabled_metadata=1' >> /etc/yum.repos.d/cmake3.repo

安装 yum install cmake3

此时安装的 cmake3 不会覆盖系统的 cmake 如果需要覆盖,可以指定别名

.bashrc 文件中添加

alias cmake=cmake3