How to set the default version of python in python2.x/python3.x

1. View the current default Python version
[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.View the python installation path:
[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. View all versions of python and soft connections
[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. Delete (backup) the soft connection
[root@docker ~]# mv /usr/bin/python /usr/bin/python.bak
5. Re-create the soft connection
[root@docker ~]# ln -s /usr/bin/python2.7 /usr/bin/python
6. Check the version again
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.
>>> 

Guess you like

Origin blog.csdn.net/Lin_Hv/article/details/106336683
Recommended