#安裝依賴
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
#下載Python3 tar包
wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz
#創建安裝位置-可忽略
mkdir -p /usr/local/python3
#解壓
tar -zxvf Python-3.9.5.tgz
#安裝gcc libffi-devel
yum install gcc
yum install libffi-devel -y
#configure and make
cd Python目錄
./configure --prefix=/usr/local/python3
./configure --prefix=/usr/local/python3 --enable-optimizations --with-ssl --enable-shared
make && make install
#創建軟連接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
#設置環境變量
vim /etc/profile
# vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
#重載環境配置
source ~/.bash_profile
