CentOS 6.9 root 安装配置卸载 Python-3.5.6

cd ~/Downloads
# 下载源码
wget https://www.python.org/ftp/python/3.5.6/Python-3.5.6.tgz
cd ~
mkdir soft
mkdir soft_src
cd soft_src
tar xzvf ~/Downloads/Python-3.5.6.tgz
# 进入源码目录
cd Python-3.5.6
# 安装前查看相关帮助信息
./configure --help
# 创建安装目录
mkdir -p ~/soft/python3
# 检查环境, 生成Makefile, prefix一定要配置, 否则会覆盖原有的python2
./configure --prefix=/root/soft/python3
# configure: error: in `/root/soft_src/Python-3.5.6':
# configure: error: no acceptable C compiler found in $PATH
# See `config.log' for more details
# 如果屏幕输出以上信息,说明缺少C的编译器,要先安装编译器
# 我们可以通过 yum -y install gcc 来安装
# 安装好gcc后,要再执行一次 ./configure --prefix=/root/soft/python3
# 再有问题再解决,解决后再执行一次,一直到屏幕输出 creating Makefile 此时当前目录下会产生一个Makefile文件
# 没有这个文件,下面的编译安装是无法进行的
make # 编译源码
make install # 安装(可以使用 make install > my_python3_install.log保存安装日志以便卸载时使用)

# 配置环境变量PATH
vim /etc/profile
export PATH=/root/soft/python3/bin:$PATH
source /etc/profile

# 查看版本, 验证安装是否成功
python3 -V

# 进入交互解释器
python3
print('hello world')
exit()

# 卸载
# 清除环境变量中的相关配置
export PATH=/root/soft/python3/bin:$PATH
# 只将上面一行删除就可
source /etc/profile
# 注销账户重新登录
# 删除 prefix 指定的目录即可,如怕有遗漏可以去分析安装日志,看一下相关的其他目录还有哪些
rm -rf /root/soft/python3
# 验证是否卸载
python3 -V

# 源码安装还有一种卸载方式
# 在编译的目录(即Makefile所在的那个目录)下
运行 make uninstall
# Makefile文件中包含卸载功能才可以使用此命令使用命令cat Makefile | grep uninstall验证
再运行 make clean
再运行 make distclean
# 验证是否卸载
python3 -V

如果无法使用 make uninstall 就只能使用分析安装日志并删除相关目录的方式卸载了
cat my_python3_install.log | grep 'Creating directory'

原文地址:https://www.cnblogs.com/kingsniper13/p/9644485.html