【linux基础】linux更改python默认版本

it2023-10-25  71

这里以centos设置python3为默认版本为例

[root@localhost ~]# python --version Python 2.7.5 [root@localhost ~]# whereis python python: /usr/bin/python /usr/bin/python2.7 /usr/bin/python3.6 /usr/bin/python3.6m /usr/bin/python2.7-config /usr/lib/python2.7 /usr/lib/python3.6 /usr/lib64/python2.7 /usr/lib64/python3.6 /etc/python /usr/local/lib/python3.6 /usr/include/python2.7 /usr/include/python3.6m /usr/share/man/man1/python.1.gz [root@localhost ~]# ll /usr/bin/python* lrwxrwxrwx. 1 root root 7 10月 27 2019 /usr/bin/python -> python2 lrwxrwxrwx. 1 root root 9 10月 27 2019 /usr/bin/python2 -> python2.7 -rwxr-xr-x. 1 root root 7216 8月 7 2019 /usr/bin/python2.7 -rwxr-xr-x. 1 root root 1835 8月 7 2019 /usr/bin/python2.7-config lrwxrwxrwx. 1 root root 16 10月 27 2019 /usr/bin/python2-config -> python2.7-config lrwxrwxrwx. 1 root root 9 10月 27 2019 /usr/bin/python3 -> python3.6 -rwxr-xr-x. 2 root root 11408 8月 8 2019 /usr/bin/python3.6 -rwxr-xr-x. 2 root root 11408 8月 8 2019 /usr/bin/python3.6m lrwxrwxrwx. 1 root root 14 10月 27 2019 /usr/bin/python-config -> python2-config

修改/usr/bin/python默认版本软链接指向的为python3

下面来操作

[root@localhost ~]# rm -rf /usr/bin/python [root@localhost ~]# ln -s /usr/bin/python3 /usr/bin/python [root@localhost ~]# ll /usr/bin/python* lrwxrwxrwx. 1 root root 16 10月 25 17:44 /usr/bin/python -> /usr/bin/python3 lrwxrwxrwx. 1 root root 9 10月 27 2019 /usr/bin/python2 -> python2.7 -rwxr-xr-x. 1 root root 7216 8月 7 2019 /usr/bin/python2.7 -rwxr-xr-x. 1 root root 1835 8月 7 2019 /usr/bin/python2.7-config lrwxrwxrwx. 1 root root 16 10月 27 2019 /usr/bin/python2-config -> python2.7-config lrwxrwxrwx. 1 root root 9 10月 27 2019 /usr/bin/python3 -> python3.6 -rwxr-xr-x. 2 root root 11408 8月 8 2019 /usr/bin/python3.6 -rwxr-xr-x. 2 root root 11408 8月 8 2019 /usr/bin/python3.6m lrwxrwxrwx. 1 root root 14 10月 27 2019 /usr/bin/python-config -> python2-config [root@localhost ~]# python --version Python 3.6.8 [root@localhost ~]#
最新回复(0)