1、下载安装包
到python的官网 https://www.python.org/downloads/source/,选个最新的Stable Releases,下载
#cd /opt
#wget https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tgz
wget如果太慢,就先用迅雷下载来,然后从本地传到linux里
解压
#tar -zxvf Python-3.10.2.tgz
#cd Python-3.10.2/
2、安装
首先安装可能的依赖项(可选)
# yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel zlib-devel
然后安装python3.10.2安装到/usr/local目录下
#./configure --prefix=/usr/local/
#make
#make altinstall
3、将/usr/bin/python链接到新安装的python3.10版本
# cd /usr/bin
# mv python python.backup
# ln -s /usr/local/bin/python3.10 /usr/bin/python
# ln -s /usr/local/bin/python3.10 /usr/bin/python3
# rm -rf /usr/bin/python2
# ln -s /usr/bin/python2.7 /usr/bin/python2
这时候执行python -V 可见默认用的是刚装的新版本。
4、yum中脚本只能用python2版本,所以需要修改脚本依赖
# cd /usr/bin
# ll yum*
可以看到有以下文件
-rwxr-xr-x 1 root root 802 Feb 9 15:32 yum
-rwxr-xr-x 1 root root 10190 Feb 9 15:33 yum-builddep
-rwxr-xr-x 1 root root 9040 Feb 9 15:33 yum-config-manager
-rwxr-xr-x 1 root root 8539 Feb 9 15:34 yum-debug-dump
-rwxr-xr-x 1 root root 7904 Feb 9 15:34 yum-debug-restore
-rwxr-xr-x 1 root root 11116 Feb 9 15:35 yumdownloader
-rwxr-xr-x 1 root root 11032 Feb 9 15:35 yum-groups-manager
将这些文件第一行#!/usr/bin/python 都改为 #!/usr/bin/python2,然后运行yum version,正常可用了。
原文链接:https://www.jianshu.com/p/c302f01ce44f