一键脚本
bashyum update -y && yum -y install gcc gcc-c++ bzip2 bzip2-devel xz-devel python-backports-lzma mesa-libGL zlib* libffi-devel openssl-devel && \ rpm -qa|grep python3|xargs rpm -ev --allmatches --nodeps && \ whereis python3 |xargs rm -frv && \ mkdir -p /data/openssl && cd /data/openssl && \ wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz && \ tar -zxvf openssl-1.1.1g.tar.gz && cd openssl-1.1.1g && \ ./config --prefix=/usr/local/openssl no-zlib && make -j8 && make install -j8 && \ mv /usr/bin/openssl /usr/bin/openssl.bak && \ mv /usr/include/openssl/ /usr/include/openssl.bak && \ ln -s /usr/local/openssl/include/openssl /usr/include/openssl && ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so && ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl && \ echo "/usr/local/openssl/lib" >> /etc/ld.so.conf && ldconfig -v && \ mkdir -p /data/python && cd /data/python && \ wget https://www.python.org/ftp/python/3.10.10/Python-3.10.10.tgz && \ tar -zxvf Python-3.10.10.tgz && cd Python-3.10.10 && \ export LANGUAGE=en_US.UTF-8 && export LANG=en_US.UTF-8 && export LC_ALL=en_US.UTF-8 && \ ./configure --prefix=/usr/local/python3 CFLAGS=-fPIC --enable-shared --with-openssl=/usr/local/openssl && make -j8 && make install -j8 && \ ln -s /usr/local/python3/bin/python3.10 /usr/bin/python3 && \ ln -s /usr/local/python3/bin/pip3.10 /usr/bin/pip3 && touch /etc/ld.so.conf.d/python3.conf && \ echo "/usr/local/python3/lib" > /etc/ld.so.conf.d/python3.conf && \ ldconfig -v && python3 -V
bashyum update -y && yum -y install gcc gcc-c++ bzip2 bzip2-devel xz-devel python-backports-lzma mesa-libGL zlib* libffi-devel openssl-devel
bashrpm -qa|grep python3|xargs rpm -ev --allmatches --nodeps && whereis python3 |xargs rm -frv
查看现有的已安装的python2:whereis python
查看现有的已安装的python3:whereis python3
bashmkdir -p /data/openssl && cd /data/openssl && wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
解压
bashtar -zxvf openssl-1.1.1g.tar.gz && cd openssl-1.1.1g
编译安装
bashmkdir /usr/local/openssl && ./config --prefix=/usr/local/openssl no-zlib && make -j8 && make install -j8
备份
bashmv /usr/bin/openssl /usr/bin/openssl.bak && mv /usr/include/openssl/ /usr/include/openssl.bak
配置软链
bashln -s /usr/local/openssl/include/openssl /usr/include/openssl && ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so && ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
修改配置并验证版本
bashecho "/usr/local/openssl/lib" >> /etc/ld.so.conf && ldconfig -v && openssl version
环境变量
bashexport LDFLAGS=" -L/usr/local/openssl/lib" && \ export CPPFLAGS=" -I/usr/local/openssl/include" && \ export PKG_CONFIG_PATH="/usr/local/openssl/lib/pkgconfig"
下载安装python-v3.10.10
bashmkdir -p /data/python && cd /data/python && wget https://www.python.org/ftp/python/3.10.10/Python-3.10.10.tgz
解压
bashtar -zxvf Python-3.10.10.tgz && cd Python-3.10.10
编译安装
bashexport LANGUAGE=en_US.UTF-8 && export LANG=en_US.UTF-8 && export LC_ALL=en_US.UTF-8 && \ ./configure --prefix=/usr/local/python3 CFLAGS=-fPIC --enable-shared --with-openssl=/usr/local/openssl && make -j8 && make install -j8
设置软链
bashln -s /usr/local/python3/bin/python3.10 /usr/bin/python && ln -s /usr/local/python3/bin/pip3.10 /usr/bin/pip
配置依赖
bashtouch /etc/ld.so.conf.d/python3.conf && echo "/usr/local/python3/lib" > /etc/ld.so.conf.d/python3.conf && ldconfig
验证版本
python2:python -V
python3:python3 -V
修改软链
备份原python
bashmv /usr/bin/python /usr/bin/python.bak && mv /usr/bin/pip /usr/bin/pip.bak
设置软链
bashln -s /usr/local/python3/bin/python3.10 /usr/bin/python && ln -s /usr/local/python3/bin/pip3.10 /usr/bin/pip
配置依赖
bashtouch /etc/ld.so.conf.d/python3.conf && echo "/usr/local/python3/lib" > /etc/ld.so.conf.d/python3.conf && ldconfig
验证版本
bashpython -V
后续:恢复yum使用python2
bashsed -i '1d' /usr/bin/yum && sed -i "1i#! /usr/bin/python2" /usr/bin/yum
bashsed -i '1d' /usr/libexec/urlgrabber-ext-down && sed -i "1i#! /usr/bin/python2" /usr/libexec/urlgrabber-ext-down
bashsed -i '1d' /usr/bin/yum-config-manager && sed -i "1i#! /usr/bin/python2 -tt" /usr/bin/yum-config-manager
本文作者:954L
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!