python2.x/python3.x如何设置python默认版本

1.查看当前默认的Python版本
[root@docker ~]# python
Python 3.6.8 (default, Apr 19 2020, 23:57:12) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
2.查看python安装路径:
[root@docker ~]# whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/local/python3/bin/python3.6m /usr/local/python3/bin/python3.6 /usr/local/python3/bin/python3.6m-config /usr/local/python3/bin/python3.6-config /usr/share/man/man1/python.1.gz
3.查看python所有版本及软连接
[root@docker ~]# ls /usr/bin/python* -l
lrwxrwxrwx. 1 root root   30 Apr 20 00:00 /usr/bin/python -> /usr/local/python3/bin/python3
lrwxrwxrwx. 1 root root    9 Apr 12 06:50 /usr/bin/python2 -> python2.7
-rwxr-xr-x. 1 root root 7216 Aug  6  2019 /usr/bin/python2.7
lrwxrwxrwx. 1 root root    7 Apr 12 06:50 /usr/bin/python_bak -> python2
4.删除(备份)软连接
[root@docker ~]# mv /usr/bin/python /usr/bin/python.bak
5.重新创建软连接
[root@docker ~]# ln -s /usr/bin/python2.7 /usr/bin/python
6.再次查看版本
root@docker ~]# python
Python 2.7.5 (default, Aug  7 2019, 00:51:29) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

你可能感兴趣的:(Python,Linux)