自学内容网 自学内容网

Ubuntu18升级cmake和python

1、升级cmake至3.22.1

某些软件包编译时需要高版本的Cmake,因此需要升级Cmake。 不能使用 sudo apt-get remove cmake卸载低版本cmake后再重装高版本,这样做会导致之前编译和安装的很多库一起被卸载!!!

正确步骤是:

1.1 去https://cmake.org/files下载所需版本的源码。也可以使用wget下载,例如:

cd /opt
wget https://cmake.org/files/v3.22/cmake-3.22.1.tar.gz

1.2 解压

tar -xzvf cmake-3.22.1.tar.gz

1.3 进入解压目录,配置成功之后显示:CMake has bootstrapped. Now run make.

chmod 777 ./configure
./configure

1.4 配置完成后,编译:

make

1.5 编译完成后,安装:

sudo make install

1.6 最后使用新安装的cmake替换旧版本,其中/usr/local/bin/cmake为新安装的cmake目录。

sudo update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force

1.7 最后测试cmake版本:

cmake --version

1.8 原理

安装之前:
在这里插入图片描述
安装之后:
在这里插入图片描述

可以看到/usr/bin目录下的cmake成为了一个软链接,指向了/etc/alternatives/cmake,而后者由指向了/usr/local/bin/cmake,也就是我们安装的版本。其实就是通过软链接的方式将原始的程序“替换”了。

2、升级python至3.8

低版本的Ubuntu官方apt库中还未收录python3.10,这里使用deadsnakes PPA库安装。

2.1 安装依赖包

sudo apt update
sudo apt install software-properties-common

2.2 添加deadsnakes PPA源

sudo add-apt-repository ppa:deadsnakes/ppa

2.3 安装python3.8

sudo apt install python3.8

python3.8 --version

2.4 将python各版本添加到update-alternatives

$ which python3.8
/usr/bin/python3.8

$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1

$ which python3.6
/usr/bin/python3.6

$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2

2.5 配置python3默认指向python3.8

$ sudo update-alternatives --config python3


There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.6   2         auto mode
  1            /usr/bin/python3.6   2         manual mode
  2            /usr/bin/python3.8   1         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2

2.6 测试python3版本

python3 --version

2.7 配置python默认指向python3

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 2

$ sudo update-alternatives --config python


There are 2 choices for the alternative python (providing /usr/bin/python3).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python2   2         auto mode
  1            /usr/bin/python2   2         manual mode
  2            /usr/bin/python3   1         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2

2.8 测试python版本

python --version

原文地址:https://blog.csdn.net/zlbdmm/article/details/142453343

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!