linux python版本切换alternatives

查看发现linux的python3命令指向alternatives

alternatives是Linux系列操作系统的一个内置命令,即使最小化安装也有该命令,它的主要作用就是版本控制切换,比如,你的系统内有多个Python版本,Python3.8,Python2.7.5,Python3.6,。

复制代码
[root@santiagod-andible openstack-ansible]# find /usr/bin/ |grep python3 |xargs -i ls -ld {}
-rwxr-xr-x 1 root root 7760 Aug 26  2021 /usr/bin/python3.9
lrwxrwxrwx 1 root root 31 Aug 25  2021 /usr/bin/python3.6 -> /usr/libexec/platform-python3.6
lrwxrwxrwx 1 root root 32 Aug 25  2021 /usr/bin/python3.6m -> /usr/libexec/platform-python3.6m
lrwxrwxrwx 1 root root 25 Aug 10 09:51 /usr/bin/python3 -> /etc/alternatives/python3
lrwxrwxrwx 1 root root 17 Aug 25  2021 /usr/bin/python3.6-config -> python3.6m-config
lrwxrwxrwx 1 root root 39 Aug 25  2021 /usr/bin/python3.6m-config -> /usr/libexec/platform-python3.6m-config
lrwxrwxrwx 1 root root 46 Aug 25  2021 /usr/bin/python3.6m-x86_64-config -> /usr/libexec/platform-python3.6m-x86_64-config
lrwxrwxrwx 1 root root 32 Aug 11 12:46 /usr/bin/python3-config -> /etc/alternatives/python3-config
-rwxr-xr-x 1 root root 57 Aug 26  2021 /usr/bin/python3.9-config
-rwxr-xr-x 1 root root 3616 Aug 26  2021 /usr/bin/python3.9-x86_64-config
复制代码

查看alternatives发现,这个链接指向又回去了

[root@santiagod-andible openstack-ansible]# find /etc/alternatives/ |grep python3|xargs -i ls -ld {}
lrwxrwxrwx 1 root root 18 Aug 10 09:51 /etc/alternatives/python3 -> /usr/bin/python3.6
lrwxrwxrwx 1 root root 34 Aug 10 09:51 /etc/alternatives/python3-man -> /usr/share/man/man1/python3.6.1.gz
lrwxrwxrwx 1 root root 25 Aug 11 12:46 /etc/alternatives/python3-config -> /usr/bin/python3.6-config

 

此时我感觉,切换默认python解释器还是通过alternatives稳妥一点,担心直接修改软链接可能会造成版本冲突

切换默认python3

复制代码
[root@santiagod-andible openstack-ansible]# alternatives --config python3

There are 2 programs which provide 'python3'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/bin/python3.6
   2           /usr/bin/python3.9

Enter to keep the current selection[+], or type selection number: 2
[root@santiagod-andible openstack-ansible]# find /etc/alternatives/ |grep python3|xargs -i ls -ld {}
lrwxrwxrwx 1 root root 18 Aug 11 13:53 /etc/alternatives/python3 -> /usr/bin/python3.9
lrwxrwxrwx 1 root root 25 Aug 11 13:53 /etc/alternatives/python3-config -> /usr/bin/python3.9-config
lrwxrwxrwx 1 root root 34 Aug 11 13:53 /etc/alternatives/python3-man -> /usr/share/man/man1/python3.9.1.gz
复制代码

 

posted @   咿呀哒喏  阅读(244)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
历史上的今天:
2022-08-11 docker和docker-compose便捷安装
点击右上角即可分享
微信分享提示