Update-alternatives can be used to create, delete, repair, and soft connections. It can also display information about existing soft connections. All of these constitute the alternatives system ).
In many cases, we install different applications with the same or similar functions on the same operating system, such as different text editors on the same operating system. This gives users of this system more choices when editing texts. If users want to, they can choose any one of them. But what if the user does not specify which editor he wants to use? It is embarrassing for a program because it has no one to make a so-called "good" choice.
However, the emergence of the alternatives System In Debian solved this problem. A common name (generic name) in the file system is shared by files with interchangeable functions, the alternative system and system administrator jointly decide which file is specified by the shared name (that is, the alternative system cannot help users manage soft connections completely, after all, people-oriented ). For example, if the text editor ed (1) and nvi (1) are installed in a system and the alternative system scheme is assumed to share the name (/usr/bin/editor) by default, it is directed to/usr/bin/nvi. Then, the system administrator can abolish this designation and direct the shared name to/usr/bin/ed. Unless otherwise specified, otherwise, the option system will not change this setting.
In fact, the shared name does not directly point to the soft connection of the selected Program (command), but to a name in the alternative directory (alternatives directory. This name is also a soft connection, which directly points to the selected Program (command ). The purpose of this mechanism is to limit the changes made by the Administrator to the corresponding configuration file in the/etc directory: FHS can well provide the benefits of doing so.
Update-alternatives is called to update the information of the corresponding file in the alternative scheme when any file (Program/package) providing specific functions is installed, deleted, or changed. Update-alternatives are often called by the psstinst (configuration) or prerm (installation) script in the Debian package.
Multiple alternatives that are synchronized for better performance are called groups. For example, when multiple versions of the vi editor are installed, the man page specified by/usr/share/man/man1/vi.1 should correspond to the vi version specified by/usr/bin/vi (different versions of vi have their own man, what we need to do is to display the man page corresponding to the vi editor we are using ).
Each link group has two different modes: automatic mode and manual mode. A group can only be one of them at any given time. If a group is in automatic mode, when the package is installed or deleted, the alternative system determines whether or not to update the corresponding link (links ). If you are in manual mode, the alternative system retains the original administrator's choice and avoids link changes (unless a broken occurs ).
When the connection group is installed to the system for the first time, it is assigned the automatic mode. If the system administrator then changes the Mode settings, the group is automatically converted to the manual mode.
Each option has its own level (priority). When a link group is in automatic mode, its members will point to high-level options.
When the -- config option is used, update-alternatives lists the master link names of all link groups. The currently selected group is marked. You can change the link direction at the prompt, but this will change the mode to manual. If you want to reply to the automatic mode, you can use the -- auto option, or -- config to reselect the Group marked as automatic.
If you do not want to use the interaction mode provided by -- config, you can also use the -- set Option (more details are provided below ).
Different packages that provide the same file need to be synchronized. In other words, the use of update-alternatives works for the involved packages.