Centos下,修改python版本,保留原2.7.5版本同时,更改默认版本为3.6
保留原版本
由于yum中会配置python版本,在进行python版本更新时,需要先将yum的配置文件都更改了。
首先,切用户
1
| mv /usr/bin/python2.7 /usr/bin/python2.7.5 # 保留默认版本python为python2.7.5
|
1
| ln -s /usr/bin/python2.7.5 /usr/local/bin/python2.7.5 # 创建软连接
|
1
| ls -al /usr/bin/yum* # 查看/usr/bin/目录下所有yum文件,共7个
|
一个一个改:
1
| #!/usr/bin/python —> #!/usr/bin/python2.7.5
|
1 2
| vi /usr/libexec/urlgrabber-ext-down # 修改/usr/libexec/目录下 urlgrabber-ext-down #!/usr/bin/python —> #!/usr/bin/python2.7.5
|
安装python3.6
安装配置环境
wget
首先检查是否有安装wget,没有则需要安装:
准备编译环境
1 2
| yum groupinstall 'Development Tools' yum install zlib-devel bzip2-devel openssl-devel ncurses-devel
|
开始安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz tar zxvf Python-3.6.2.tgz cd Python-3.6.2 ./configure make all make install make clean make distclean rm -rf /usr/bin/python rm -rf /usr/bin/python3 rm -rf /usr/bin/python3.6 ln -s /usr/local/bin/python3.6 /usr/bin/python ln -s /usr/local/bin/python3.6 /usr/bin/python3 ln -s /usr/local/bin/python3.6 /usr/bin/python3.6 /usr/bin/python -V /usr/bin/python3 -V /usr/bin/python3.6 -V rm -rf /usr/local/bin/python rm -rf /usr/local/bin/python3 ln -s /usr/local/bin/python3.6 /usr/local/bin/python ln -s /usr/local/bin/python3.6 /usr/local/bin/python3 python -V python3 -V python3.6 -V
|
[root@localhost Python-3.6.2]# python -V
Python 3.6.2
[root@localhost Python-3.6.2]# python3 -V
Python 3.6.2
[root@localhost Python-3.6.2]# python3.6 -V
Python 3.6.2
```
安装成功~
> [参考链接](https://blog.csdn.net/hu19921016/article/details/72236966)