使用 alternatives 管理多版本软件

今天装 you-get 的时候发现需要 python3,安装 python3 的时候发现了 python 的路径是这样的

$ ll /usr/bin/python
lrwxrwxrwx 1 root root 24 3 月   9 13:28 /usr/bin/python -> /etc/alternatives/python
$ ll /etc/alternatives/python
lrwxrwxrwx 1 root root 18 3 月   9 15:25 /etc/alternatives/python -> /usr/bin/python2.7

不知道为什么 linux 要这样处理,好像以前也碰到过这个现象,但是当时都是直接做的链接,这次 google 了一下才知道这是一个多版本软件管理的工具。

将 python2 和 python3 注册到 alternatives 中

 $ update-alternatives --install /usr/bin/python python /usr/bin/python2.7 100
 $ update-alternatives --install /usr/bin/python python /usr/bin/python3.3 101

然后看看注册结果:

$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.3   6         auto mode
* 1            /usr/bin/python2.7   5         manual mode
  2            /usr/bin/python3.3   6         manual mode

Press enter to keep the current choice*], or type selection number: 

这里输入你要的版本的序号就可以了。

不对吧。

确实有 alternatives。但是 python 不需要用这个。

python 一般是 /usr/bin 下面直接 python 和 python3 分别指向 2.7 和 3.3 的。

不是啊,我的是用了 alternatives 的,然后我改成直接链接了,现在又改回来了。

我的有 alternative,但是 python 不是。我也觉得一般 python 不需要。