Centos 安装 python3

Linux 4个月前
0

一、更新源

sudo yum update

二、如果安装全家桶编译环境,执行如下命令:

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

三、官网下载源文件

wget "https://www.python.org/ftp/python/3.12.2/Python-3.12.2.tar.xz"

四、解压安装

# 解压

tar -xf Python-3.12.2.tar.xz

cd Python-3.12.2

./configure --prefix=/home/kmgog/Python-3.12.2 --with-ssl

# 编译

make

# 安装

sudo make install

五、添加软连接

sudo ln -s /home/kmgog/Python-3.12.2 /usr/bin/python3

六、添加环境变量

vim ~/.bash_profile

i

esc

:wq

export PATH=/usr/bin/python3:$PATH

#使更改生效

source ~/.bash_profile

python --version

七、删除/卸载 python3

#使用rpm卸载python3

rpm -qa|grep python3|xargs rpm -ev --allmatches --nodeps

#删除所有残余文件

whereis python3 |xargs rm -frv

#查看现有安装的python,验证是否删除干净

whereis python