下载python源码包
网址:https://www.python.org/downloads/release/python-362/
下载地址:https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
安装库环境
[root@localhost opt]# 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
下载并解压安装包
[root@localhost opt]# wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
[root@localhost opt]# tar -xf Python-3.6.2.tgz
进入到解压后的目录中
[root@localhost opt]# cd python36/
[root@localhost python36]# ./configure --prefix=/opt/python36
[root@localhost python36]# make && make install
添加环境变量
查看环境变量
[root@localhost opt]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin
添加python3的工作目录
[root@localhost python36]#PATH="/opt/python36/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin"
添加path变量到全局配置文件中,每次开机就加载,在/etc/profile最后一行添加
PATH="/opt/python36/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin"
然后
source /etc/profile