目录
1 apt方式安装
sudo apt install cmake
这种方式最方便,但是这种方式安装的cmake往往版本比较低,不能满足要求,一般都要用自己源码安装
2 源码安装
当我们编译提示cmake版本较低时就要用这种方式手动安装,
2.1 首先卸载掉ubutnu原来的cmake
sudo apt-get remove cmake
2.2 下载cmake源码包
去 https://cmake.org/download/ 下载cmake自己想要的版本,我这里下载的是cmake-3.19.0-rc3.tar.gz
2.3 解压文件
tar -zxvf cmake-3.19.0-rc3.tar.gz
2.4 执行bootstrap
./bootstrap
我执行到这一步之后报错:
make: 'cmake' is up to date.
loading initial cache file /data/software_package/cmake-3.19.0-rc3/Bootstrap.cmk/InitialCacheFlags.cmake
-- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR)
CMake Error at Utilities/cmcurl/CMakeLists.txt:505 (message):
Could not find OpenSSL. Install an OpenSSL development package or
configure CMake with -DCMAKE_USE_OPENSSL=OFF to build without OpenSSL.
-- Configuring incomplete, errors occurred!
See also "/data/software_package/cmake-3.19.0-rc3/CMakeFiles/CMakeOutput.log".
See also "/data/software_package/cmake-3.19.0-rc3/CMakeFiles/CMakeError.log".
---------------------------------------------
Error when bootstrapping CMake:
Problem while running initial CMake
于是先执行下面的命令安装ssl之后再执行./bootstarp
sudo apt install libssl-dev
2.5 编译安装
make -j8
make install
2.6 查看是否安装成功
cmake --version
3 安装包方式安装
某次在某个项目中,我想升级cmake,然后按照上面的源码安装方式安装,老是有个报错,
Error at Utilities/cmlibarchive/CMakeLists.txt:1660 (MESSAGE): pid_t doesn't exist on this platfor
我试了好几个方法没有解决,好吧,直接换安装方法
下载二进制包
下载完这两个之后,直接运行
./cmake-3.26.5-linux-x86_64.sh --prefix=/usr/local
然后
cmake --version