alternatives 使用笔记
fedora23 X64 系统里有多个版本的 python ,默认使用的是 python2.7
$ ls -l /usr/bin/python* lrwxrwxrwx. 1 root root 24 Mar 26 15:49 /usr/bin/python -> /usr/bin/python2 lrwxrwxrwx. 1 root root 9 Jun 20 2016 /usr/bin/python2 -> python2.7 -rwxr-xr-x. 1 root root 7088 Jun 20 2016 /usr/bin/python2.7 lrwxrwxrwx. 1 root root 9 Jun 29 2015 /usr/bin/python3 -> python3.4 -rwxr-xr-x. 2 root root 11184 Jun 29 2015 /usr/bin/python3.4 -rwxr-xr-x. 2 root root 11184 Jun 29 2015 /usr/bin/python3.4m -rwxr-xr-x. 1 root root 308 Jun 19 2015 /usr/bin/python3-chardetect -rwxr-xr-x. 1 root root 301 Sep 28 2015 /usr/bin/python3-coverage -rwxr-xr-x. 1 root root 301 Jun 19 2015 /usr/bin/python3-mako-render -rwxr-xr-x. 1 root root 43 Jun 19 2015 /usr/bin/python3-pyinotify
现在想切换到默认使用 python3.4 ,考虑使用 alternatives 命令,用 alternatives --display python 发现 python 没有在 alternatives 的管理列表,将不同版本的 python 添加到alternatives 下,使用方法 usage: alternatives --install <link> <name> <path> <priority>
$ alternatives --install /usr/bin/python python /usr/bin/python2.7 1 $ alternatives --install /usr/bin/python python /usr/bin/python3.4 2
查看 alternatives --display python
$ alternatives --display python python - status is auto. link currently points to /usr/bin/python3.4 /usr/bin/python2.7 - priority 1 /usr/bin/python3.4 - priority 2 Current `best' version is /usr/bin/python3.4.
可以看到已经通过 alternatives 指向了 python3.4
$ ls -l /usr/bin/python* lrwxrwxrwx. 1 root root 24 Mar 26 15:49 /usr/bin/python -> /etc/alternatives/python lrwxrwxrwx. 1 root root 9 Jun 20 2016 /usr/bin/python2 -> python2.7 -rwxr-xr-x. 1 root root 7088 Jun 20 2016 /usr/bin/python2.7 lrwxrwxrwx. 1 root root 9 Jun 29 2015 /usr/bin/python3 -> python3.4 -rwxr-xr-x. 2 root root 11184 Jun 29 2015 /usr/bin/python3.4 -rwxr-xr-x. 2 root root 11184 Jun 29 2015 /usr/bin/python3.4m -rwxr-xr-x. 1 root root 308 Jun 19 2015 /usr/bin/python3-chardetect -rwxr-xr-x. 1 root root 301 Sep 28 2015 /usr/bin/python3-coverage -rwxr-xr-x. 1 root root 301 Jun 19 2015 /usr/bin/python3-mako-render -rwxr-xr-x. 1 root root 43 Jun 19 2015 /usr/bin/python3-pyinotify
$ ls -l /etc/alternatives/python lrwxrwxrwx. 1 root root 18 Mar 26 15:49 /etc/alternatives/python -> /usr/bin/python3.4
再进行切换使用 alternatives --config python
$alternatives --config python
There are 2 programs which provide 'python'. Selection Command ----------------------------------------------- * 1 /usr/bin/python2.7 + 2 /usr/bin/python3.4 Enter to keep the current selection[+], or type selection number:
选择所需要切换的版本对应的数字编号即可。
注:
update-alternatives 与 alternatives 是同一个命令
$ ls -l /usr/sbin/update-alternatives lrwxrwxrwx. 1 root root 12 Oct 2 2015 /usr/sbin/update-alternatives -> alternatives
[1] https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux