Linux下python默认版本切换
1.查看默认版本
python --version
root@ubuntu:/usr/bin# python --version
Python 2.7.15
2.查看版本列表
update-alternatives --list python
1.如果版本只有一个,在进行添加一个,用于切换,不然不能进行切换
例如:
root@ubuntu:/home/test# update-alternatives --list python
/usr/bin/python2.7
添加:
update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
后面的Python3.6 2 中间有一个空格,后面的2表示序列号,在后面切换中可以看到
root@ubuntu:/usr/bin# update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
(#系统返回)update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python (python) in auto mode
root@ubuntu:/usr/bin# update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.6
3.切换默认版本
update-alternatives --config python
切换:root@ubuntu:/usr/bin# update-alternatives --config python
选择:Press to keep the current choice[*], or type selection number: 2
再次查看默认版本:root@ubuntu:/usr/bin# python
root@ubuntu:/usr/bin# update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.2 3 auto mode
1 /usr/bin/python2.7 1 manual mode
2 /usr/bin/python3.6 3 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
root@ubuntu:/usr/bin# python
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>