centos6.9
查看当前版本
[root@VM_0_15_centos ~]# python -V Python 2.6 [root@VM_0_15_centos ~]# which python /usr/local/bin/python
安装相关软件
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
官网下载Py 3.6.6
[root@VM_0_15_centos ~]# wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz
解压安装
[root@VM_0_15_centos ~]# tar xf Python-3.6.6.tgz [root@VM_0_15_centos ~]# cd Python-3.6.6
[root@VM_0_15_centos Python-3.6.6]# ./configure
[root@VM_0_15_centos Python-3.6.6]# make && make install
现在有Python3了
[root@VM_0_15_centos ~]# python3 Python 3.6.6 (default, Oct 18 2018, 16:08:12) [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> quit()
可以把原来的软链接改个名, 新建指向Python3的软连接
cd /usr/local/bin/ ###这个路径是 which python 的结果路径 mv python python-2 ln -s /usr/local/bin/python3 python
[root@VM_0_15_centos bin]# python Python 3.6.6 (default, Oct 18 2018, 16:08:12) [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> quit()
因为yum需要执行python2脚本,所以还要修改yum的配置
[root@VM_0_15_centos bin]# vim /usr/bin/yum #!/usr/bin/python2.6