Since the development of Linux, there have been a lot of available software. In this way, some software functions are basically the same. For example, there are nvi, Vim, emacs, and nano in the editor. What I'm talking about is only part of it. In most cases, software with similar functions is installed in the system at the same time and can be executed using their names. For example, to execute vim, you only need to input Vim in the terminal and press Enter. However, in some cases, we need to use a relatively fixed command to call one of these programs. For example, when we write a script program, we only need to write the editor, instead of worrying about "which editor is. Debian provides a mechanism to solve this problem, and update-alternatives is used to implement this mechanism.
1) The first parameter to be introduced is -- display. It allows us to see all the optional commands for a command. Run:
Update-alternatives -- Display Editor
We can see all the commands on my machine that can be used for the editor link.
2) -- config. This option allows us to select one of the command programs as the editor and execute:
Update-alternatives -- config Editor
First, update-alternatives are automatically called by installation scripts such as postinst and prerm. Therefore, there are two statuses of an alternative: automatic and manual. The initial status of each alternative is automatic. If the system finds that the Administrator has manually modified an alternative, its status will change from automatic to manual, so that the installation script will not update it. If you want to change an alternative back to automatic, you only need to execute the Code:
Update-alternatives -- Auto Editor
General name -- this refers to the "public" names (including absolute paths) of a series of programs with similar functions, such as/usr/bin/Editor.
Link -- this refers to the name of alternative in/etc/alternative, such as editor.
Alternative -- as the name implies, this refers to the path (including the absolute path) of an optional program, such as/usr/bin/vim.
-Auto, -- display, and -- config are all linked. The third concept is priority. This is relatively simple. Of course, the higher the priority, the better the program. The last concept is master and slave alternative. Think about it. You linked/usr/bin/editor to VIM. But when you run man editor, you see the manpage of Emacs. What do you think? This introduces the concept of master and slave alternative: when the master's alternative is updated, the slave's alternative will also be updated.
Two other options:
The first one is -- install. The format is: code:
Update-alternatives -- install Gen link alt pri [-- slave sgen slink salt]...
Gen, Link, ALT, and PRI are what we have mentioned above. If you want to use alternative, you can add -- slave to the backend. If you add new alternatives to an existing alternative group, this command adds these alternatives to the list of existing alternative groups, use the new optional command as the new command; otherwise, a new automatic alternative group will be created.
Whining! I added an incorrect alternative. I don't want this alternative anymore. In this case
You can run the following command: code:
Update-alternatives -- remove name path