代码
版本3.9.6
#!/bin/bash
# 更新系统并安装开发工具
sudo yum groupinstall -y "Development Tools"
sudo yum install -y epel-release
sudo yum install -y wget zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
# 下载并安装 OpenSSL
cd /opt
# 检查 OpenSSL 安装包是否存在
if [ ! -f "openssl-1.1.1l.tar.gz" ]; then
wget https://www.openssl.org/source/openssl-1.1.1l.tar.gz
fi
# 解压并安装 OpenSSL
tar xzf openssl-1.1.1l.tar.gz
cd openssl-1.1.1l
sudo ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib
sudo make
sudo make install
echo "/usr/local/ssl/lib" | sudo tee -a /etc/ld.so.conf.d/openssl-1.1.1l.conf
# 删除 OpenSSL 安装包
cd /opt
rm -f openssl-1.1.1l.tar.gz
# 下载并安装 Python
cd /opt
# 检查 Python 安装包是否存在
if [ ! -f "Python-3.9.6.tgz" ]; then
sudo wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
fi
# 解压并安装 Python
sudo tar xzf Python-3.9.6.tgz
cd Python-3.9.6
sudo ./configure --enable-optimizations
sudo make altinstall
# 删除 Python 安装包
cd /opt
rm -f Python-3.9.6.tgz
# 创建 pip 配置文件
mkdir -p ~/pip
cat <<EOL > ~/pip/pip.conf
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
EOL
echo "安装完成!"
版本3.10.0
#!/bin/bash
# 更新系统并安装开发工具
sudo yum groupinstall -y "Development Tools"
sudo yum install -y epel-release
sudo yum install -y wget zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
# 下载并安装 OpenSSL
cd /opt
# 检查 OpenSSL 安装包是否存在
if [ ! -f "openssl-1.1.1l.tar.gz" ]; then
wget https://www.openssl.org/source/openssl-1.1.1l.tar.gz
fi
# 解压并安装 OpenSSL
tar xzf openssl-1.1.1l.tar.gz
cd openssl-1.1.1l
sudo ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib
sudo make
sudo make install
echo "/usr/local/ssl/lib" | sudo tee -a /etc/ld.so.conf.d/openssl-1.1.1l.conf
# 更新库路径
sudo ldconfig
# 删除 OpenSSL 安装包
cd /opt
rm -f openssl-1.1.1l.tar.gz
# 下载并安装 Python 3.10
cd /opt
# 检查 Python 3.10 安装包是否存在
if [ ! -f "Python-3.10.0.tgz" ]; then
sudo wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tgz
fi
# 解压并安装 Python 3.10
sudo tar xzf Python-3.10.0.tgz
cd Python-3.10.0
sudo ./configure --enable-optimizations --with-openssl=/usr/local/ssl
sudo make altinstall
# 删除 Python 安装包
cd /opt
rm -f Python-3.10.0.tgz
# 创建 pip 配置文件
mkdir -p ~/pip
cat <<EOL > ~/pip/pip.conf
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
EOL
echo "安装完成!"
评论区