UBUNTU环境下Cmake版本 更改 升级

Ubuntu CMake 版本升级
本文介绍如何在Ubuntu环境中升级CMake版本。通过下载指定版本的CMake压缩包并解压,创建软链接到/usr/bin/目录下,从而覆盖系统默认版本,实现版本更新。

UBUNTU环境下Cmake版本 更改 升级

通过apt安装的版本较低

sudo apt-get install cmake

官方给出的: https://cmake.org/download/

The release was packaged with CPack which is included as part of the release. The .sh files are self extracting gziped tar files. To install a .sh file, run it with /bin/sh and follow the directions. The OS-machine.tar.gz files are gziped tar files of the install tree. The OS-machine.tar.Z files are compressed tar files of the install tree. The tar file distributions can be untared in any directory. They are prefixed by the version of CMake. For example, the Linux-x86_64 tar file is all under the directory cmake–Linux-x86_64. This prefix can be removed as long as the share, bin, man and doc directories are moved relative to each other. To build the source distributions, unpack them with zip or tar and follow the instructions in Readme.txt at the top of the source tree.

翻译过来:

该发行版与CPack打包在一起,而CPack包含在发行版中。.sh文件是自解压缩gzip压缩的tar文件。要安装.sh文件,请使用/ bin / sh运行该文件并按照说明进行操作。OS-machine.tar.gz文件是安装树的gzip压缩tar文件。OS-machine.tar.Z文件是安装树的压缩tar文件。tar文件发行版可以在任何目录中解压。它们以CMake版本作为前缀。例如,Linux-x86_64 tar文件都在cmake–Linux-x86_64目录下。**只要share,bin,man和doc目录相对于彼此移动,就可以删除此前缀。**要构建源发行版,请使用zip或tar解压缩它们,并按照源树顶部的Readme.txt中的说明进行操作。

因此只需要将其软链接到/usr/bin/中覆盖系统原始的cmake即可实现版本替换。

wget -P /opt/ https://cmake.org/files/v3.14/cmake-3.14.0-Linux-x86_64.tar.gz
tar zxvf /opt/cmake-3.14.0-Linux-x86_64.tar.gz -C /opt
cd /opt/cmake-3.14.0-Linux-x86_64
ln -sf /opt/cmake-3.14.0-Linux-x86_64/bin/* /usr/bin/

cmake --version

echo "done"

详细请参照参考资料

参考资料:
https://blog.youkuaiyun.com/whutshiliu/article/details/106480024
http://www.cmake.org/files

<think> 嗯,用户想了解在Ubuntu系统中提高CMake版本的方法。根据提供的参考资料,我需要整理出可靠的升级方案。 用户可能正在开发一个需要新版CMake特性的项目,但Ubuntu仓库中的版本较旧。从引用[1]可以看出,CMake是跨平台的构建工具,安装方法有两种主流方式。引用[2]提到Ubuntu在文件管理和权限控制上有优势,这对编译安装很重要。 现在考虑具体方案。首先是APT方式,引用[1]和[4]都提到了通过官方仓库安装,但需要确认仓库版本是否足够新。如果不够,引用[3]详细记录了源码编译安装的完整流程:包括下载脚本、移动目录、修改权限、安装执行、创建软连接等关键步骤。引用[4]还补充了卸载旧版和安装依赖的操作,这对避免冲突很重要。 用户可能需要考虑版本选择。引用[3]使用3.31.0版本为例,实际应选择稳定新版。环境变量配置也很关键,通过软链接或PATH设置才能确保系统识别新版。 安全方面要提醒用户:编译安装需要sudo权限,操作需谨慎。最后要验证版本,如引用[3]末尾的cmake --version命令。 用户可能还需要知道如何回滚,这需要保留旧版或记录原始路径。不过引用没有提及这点,暂时不纳入回答。 </think> 在Ubuntu系统中升级CMake版本主要有两种可靠方法,具体操作如下: ### 方法1:APT安装(推荐简便方式) ```bash # 添加官方Kitware仓库(包含较新版本) sudo apt-get update sudo apt-get install -y software-properties-common sudo add-apt-repository -y ppa:kitware/cmake sudo apt-get update # 安装指定版本(例如3.28+) sudo apt-get install -y cmake # 验证安装 cmake --version ``` > 此方法通过官方PPA源安装预编译包,安全高效[^1][^2]。 ### 方法2:源码编译安装(获取最新版) ```bash # 1. 卸载旧版并安装依赖 sudo apt-get autoremove cmake sudo apt-get install -y build-essential libssl-dev wget # 2. 下载最新源码(替换版本号) wget https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3.tar.gz tar -xzvf cmake-*.tar.gz cd cmake-* # 3. 编译安装(约15-30分钟) ./bootstrap make -j$(nproc) sudo make install # 4. 验证版本 cmake --version # 应显示3.28.3 ``` > 源码编译可获取最新特性,但需手动管理版本升级[^3][^4]。 ### 关键注意事项 1. **路径优先级**:若同时存在多版本,使用`which cmake`确认调用路径 2. **环境变量**:源码安装后建议添加`export PATH=/usr/local/bin:$PATH`到`~/.bashrc` 3. **版本冲突**:使用`sudo update-alternatives --config cmake`管理多版本切换 4. **依赖验证**:编译前务必安装`libssl-dev`等依赖,避免功能缺失[^4] > 对于大多数开发场景,PPA安装(方法1)是最佳选择;仅当需要特定新特性时建议源码编译[^1][^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值