It is possible for several programs fulfilling the same or similar functions to be installed on a single system at the same time. For example, many systems have several text editors installed at once. This gives choice to the users of a system, allowing each to use a different editor, if desired, but makes it difficult for a program to make a good choice for an editor to invoke if the user has not specified a particular preference.
whereis editor (当输入editor命令时,调用的是/usr/bin的edior命令,因为PATH路径中包含/usr/bin)
editor: /usr/bin/editor /usr/bin/X11/editor /usr/share/man/man1/editor.1.gz
ls /usr/bin/editor -al
lrwxrwxrwx 1 root root 24 May 12 2013 /usr/bin/editor -> /etc/alternatives/editor
ls /usr/bin/editor -al
lrwxrwxrwx 1 root root 18 May 12 2013 /etc/alternatives/editor -> /usr/bin/vim.gnome(editor命令最终是调用/usr/bin/vim.gnome)
update-alternatives 用于配置 /etc/alternatives 对应命令的可选调用路径
例如:
查看editor命令的候选选项
sudo update-alternatives --display editor
editor - auto mode
link currently points to /usr/bin/vim.gnome
/bin/ed - priority -100
slave editor.1.gz: /usr/share/man/man1/ed.1.gz
/bin/nano - priority 40
slave editor.1.gz: /usr/share/man/man1/nano.1.gz
/usr/bin/vim.basic - priority 30
slave editor.1.gz: /usr/share/man/man1/vim.1.gz
slave editor.fr.1.gz: /usr/share/man/fr/man1/vim.1.gz
slave editor.it.1.gz: /usr/share/man/it/man1/vim.1.gz
slave editor.pl.1.gz: /usr/share/man/pl/man1/vim.1.gz
slave editor.ru.1.gz: /usr/share/man/ru/man1/vim.1.gz
/usr/bin/vim.gnome - priority 60
slave editor.1.gz: /usr/share/man/man1/vim.1.gz
slave editor.fr.1.gz: /usr/share/man/fr/man1/vim.1.gz
slave editor.it.1.gz: /usr/share/man/it/man1/vim.1.gz
slave editor.pl.1.gz: /usr/share/man/pl/man1/vim.1.gz
slave editor.ru.1.gz: /usr/share/man/ru/man1/vim.1.gz
/usr/bin/vim.tiny - priority 10
slave editor.1.gz: /usr/share/man/man1/vim.1.gz
slave editor.fr.1.gz: /usr/share/man/fr/man1/vim.1.gz
slave editor.it.1.gz: /usr/share/man/it/man1/vim.1.gz
slave editor.pl.1.gz: /usr/share/man/pl/man1/vim.1.gz
slave editor.ru.1.gz: /usr/share/man/ru/man1/vim.1.gz
Current 'best' version is '/usr/bin/vim.gnome'.
(editor 命令的候选选项有6个,当前链接为/usr/bin/vim.gnome)
增加命令的候选选项
sudo update-alternatives --install /usr/bin/editor editor /usr/bin/gedit 300
/usr/bin/editor : generic name (or alternative link)
A name, like /usr/bin/editor, which refers, via the alternatives system, to one of a number of files of similar function.
editor: alternative name. The name of a symbolic link in the alternatives directory.
/usr/bin/gedit : path
300: priority(默认选中优先级最高的)
更改命令的链接选项
sudo update-alternatives --config editor
There are 5 choices for the alternative editor (providing /usr/bin/editor).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/vim.gnome 60 auto mode
1 /bin/ed -100 manual mode
2 /bin/nano 40 manual mode
3 /usr/bin/vim.basic 30 manual mode
4 /usr/bin/vim.gnome 60 manual mode
5 /usr/bin/vim.tiny 10 manual mode
Press enter to keep the current choice[*], or type selection number:(输入你要选定的选项)