本文所有命令以root用户执行,若非root用户,请注意适时使用sudo提权。
安装编译需要的依赖包
apt update
apt install -y \
build-essential \
wget \
libssl-dev \
zlib1g-dev \
libncurses-dev \
libreadline-dev \
libsqlite3-dev \
libgdbm-dev \
libdb5.3-dev \
libbz2-dev \
libexpat1-dev \
liblzma-dev \
tk-dev \
libffi-dev \
libgmp3-dev \
libbz2-dev \
libgdbm-compat-dev
下载并编译安装Python3.12.1
curl https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tgz -o /tmp/Python-3.12.1.tgz
tar -xf /tmp/Python-3.12.1.tgz -C /tmp
cd /tmp/Python-3.12.1
./configure --enable-optimizations --prefix=/usr/local/python-3.12.1/
make -j$(nproc)
make altinstall