能正常显示版本,说明已安装cmake。
[root@DESKTOP-MLOFRB3 ~]# cmake --version
cmake version 2.8.12.2
若已安装版本以满足我们需求,则不需要更新安装。 如果已安装版本不符合我们需求,下卸载旧版:
[root@DESKTOP-MLOFRB3 ~]# yum remove -y cmake
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Resolving Dependencies
--> Running transaction check
---> Package cmake.x86_64 0:2.8.12.2-2.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================
Package Arch Version Repository Size
=============================================================================================
Removing:
cmake x86_64 2.8.12.2-2.el7 @base 27 M
Transaction Summary
=============================================================================================
Remove 1 Package
Installed size: 27 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : cmake-2.8.12.2-2.el7.x86_64 1/1
Verifying : cmake-2.8.12.2-2.el7.x86_64 1/1
Removed:
cmake.x86_64 0:2.8.12.2-2.el7
Complete!
[root@DESKTOP-MLOFRB3 ~]#
前往官网CMake下载我们需要的版本,我们下载最新稳定版3.26.4并安全验证。
[root@DESKTOP-MLOFRB3 cmake]# curl -OL https://cmake.org/files/v3.26/cmake-3.26.4-SHA-256.txt
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1646 100 1646 0 0 1239 0 0:00:01 0:00:01 --:--:-- 1257
[root@DESKTOP-MLOFRB3 cmake]# curl -OL https://cmake.org/files/v3.26/cmake-3.26.4.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 10.1M 100 10.1M 0 0 16232 0 0:10:57 0:10:57 --:--:-- 45948
[root@DESKTOP-MLOFRB3 cmake]# ll
total 10436
-rw-r--r-- 1 root root 1646 Jun 15 14:55 cmake-3.26.4-SHA-256.txt
-rw-r--r-- 1 root root 10669686 Jun 15 15:07 cmake-3.26.4.tar.gz
[root@DESKTOP-MLOFRB3 cmake]# sha256sum -c cmake-3.26.4-SHA-256.txt
# 其他版本未找到日志已忽略
cmake-3.26.4.tar.gz: OK
sha256sum: WARNING: 16 listed files could not be read
[root@DESKTOP-MLOFRB3 cmake]#
解压cmake安装包,编译安装,需要等待一段时间。
[root@DESKTOP-MLOFRB3 cmake]# tar zxvf cmake-3.26.4.tar.gz && cd cmake-3.26.4
[root@DESKTOP-MLOFRB3 cmake]# ./bootstrap && gmake && gmake install
注意此处如出现如下提示,是因为缺少c/c++编译环境:
[root@DESKTOP-MLOFRB3 cmake-3.26.4]# ./bootstrap && gmake && gmake install --------------------------------------------- CMake 3.26.4, Copyright 2000-2023 Kitware, Inc. and Contributors --------------------------------------------- Error when bootstrapping CMake: Cannot find appropriate C compiler on this system. Please specify one using environment variable CC. See cmake_bootstrap.log for compilers attempted. --------------------------------------------- Log of errors: /home/work/cmake-3.26.4/Bootstrap.cmk/cmake_bootstrap.log ---------------------------------------------
需要gcc编译环境,可参考:
我安装中遇到如下错误:
CMake Error at Utilities/cmcurl/CMakeLists.txt:608 (message):
Could not find OpenSSL. Install an OpenSSL development package or configure CMake with -DCMAKE_USE_OPENSSL=OFF to build without OpenSSL.
原因是在
Utilities/cmcurl/CMakeLists.txt
文件608行,要是用到SSL
, 而本机没有安装:if(CURL_USE_OPENSSL)
find_package(OpenSSL)
if(NOT OpenSSL_FOUND)
message(FATAL_ERROR
"Could not find OpenSSL. Install an OpenSSL development package or "
"configure CMake with -DCMAKE_USE_OPENSSL=OFF to build without OpenSSL.")
endif()
...参考这里安装:
安装完成后,确认cmake为我们要安装的版本,然后建立软链接,以便直接使用。
[root@DESKTOP-MLOFRB3 cmake-3.26.4]# /usr/local/bin/cmake --version
cmake version 3.26.4
CMake suite maintained and supported by Kitware (kitware.com/cmake).
[root@DESKTOP-MLOFRB3 cmake-3.26.4]# ln -s /usr/local/bin/cmake /usr/bin
[root@DESKTOP-MLOFRB3 cmake-3.26.4]# cmake --version
cmake version 3.26.4
CMake suite maintained and supported by Kitware (kitware.com/cmake).
[root@DESKTOP-MLOFRB3 cmake-3.26.4]#
下载离线包:
解压软件包。
cmake可执行性文件 : cmake-3.28.0-linux-x86_64/bin/cmake
cmake-gui界面: cmake-3.28.0-linux-x86_64/bin/cmake-gui
配置环境变量:
gedit ~/.bashrc
# 添加内容,PATH路径根据真实路径
export PATH=/home/sogrey/cmake-3.28.0-linux-x86_64/bin:$PATH
# 更新bashrc
source ~/.bashrc
查看是否安装成功
cmake --version
根据系统架构选择不同的下载链接。
# x86使用
curl -O https://cmake.org/files/v3.28/cmake-3.28.0-linux-x86_64.sh
# aarch64使用
curl -O https://cmake.org/files/v3.28/cmake-3.28.0-linux-aarch64.sh
执行安装脚本安装CMake,默认安装到/usr/local目录下。
sudo mkdir /usr/local/cmake-3.28.0
# sudo bash cmake-3.28.0-Linux-*.sh --prefix=/usr/local/cmake-3.28.0 --exclude-subdir
sudo bash cmake-3.28.0-linux-x86_64.sh --prefix=/usr/local/cmake-3.28.0 --exclude-subdir
配置环境变量
sudo gedit ~/.bashrc
# 添加内容,PATH路径根据真实路径
export PATH=/usr/local/cmake-3.28.0/bin:${PATH}
# 更新bashrc
source ~/.bashrc
查看是否安装成功
cmake --version
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/ $(lsb_release -cs) main"
sudo apt-get install cmake -y