1.解决编译环境的环境依赖, 必须保证这里正确安装,方可执行后续步骤
yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
2.下载源代码
网址:https://www.python.org/downloads/release/python-362/
下载地址:https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
3.解压缩源代码
tar -xf Python-3.6.2.tgz
# -x 解压参数
# -f 指定一个压缩文件,写在最后
4.切换到python源代码的目录
cd Python-3.6.2
5. 编译软件三步曲
第一步: 释放 makefile 编译文件. 如果 makefile 文件存在 ,直接执行第二步
./configure --prefix=/opt/python36/
# --prefix 告诉编译器,软件安装到哪里
第二步和第三步:
make && make install
软件安装完毕!
配置linux的环境变量,加入python3
[root@localhost /]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/opt/tnginx220/sbin:/root/bin
[root@localhost /]# PATH='/opt/python36/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin'
#添加这个PATH变量到全局配置文件中,每次开机就加载,永久生效
[root@localhost /]# vim /etc/profile
#在最底行写入
PATH="/opt/python36/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/r oot/bin"
# 退出会话,重新登录,使得/etc/profile生效