一、源码安装
1.1下载源码包
[root@rancher app]# wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
1.2解压并重命名
[root@rancher app]# tar -zxvf Python-2.7.18.tgz -C /data/app
[root@rancher app]# mv Python-2.7.18 python27
1.3 编译安装
[root@rancher app]# yum install gcc g++ make
[root@rancher app]# cd python27
[root@rancher python27]# pwd
/data/app/python27
[root@rancher python27]# ./configure --prefix=/data/app/python27
[root@rancher python27]# make && make install
1.4创建软链接和设置环境变量
[root@rancher python27]ln -s /data/app/python27/bin/python2.7 /usr/bin/python
[root@rancher python27]ln -s /data/data/python27/bin/python2.7 /usr/bin/python2
[root@rancher bin]# vim /etc/profile
####Python_HOME
export PYTHON_HOME=/data/app/python27
[root@rancher bin]# source /etc/profile
1.5 查看python版本
[root@rancher bin]# python2 --version
Python 2.7.5