然后更新系统环境
yum -y groupinstall "Development tools" yum install -y ncurses-devel gdbm-devel xz-devel sqlite-devel tk-devel uuid-devel readline-devel bzip2-devel libffi-devel
下载源码:
cd /usr/src wget https://www.python.org/ftp/python/3.8.18/Python-3.8.18.tar.xz
解压:
tar -xvJf Python-3.8.18.tar.xz
进入目录:
cd Python-3.8.18
编译:
./configure --enable-shared prefix=/usr/local/python3 --with-openssl=/usr/local/openssl-1.1.1t make && make install
查找软连接
# 查找 ll /usr/bin/ |grep python ll /usr/bin/ |grep pip
# 删除
rm -rf /usr/bin/python rm -rf /usr/bin/pip
重建软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
确认效果
python -V pip --version
此时python默认已经是3.11,但CentOS yum 还是依赖Python2.7,需要修改 yum 相关配置文件,确保yum 依然能够正常运行
将/usr/bin/yum的顶部的:
!/usr/bin/python 改成 !/usr/bin/python2.7
将/usr/libexec/urlgrabber-ext-down的顶部的:
/usr/bin/python 改为 /usr/bin/python2.7
将/usr/bin/yum-config-manager的顶部的
#!/usr/bin/python 改为 #!/usr/bin/python2.7
完成。