Debian Alternatives System:update-alternatives

Source: Internet
Author: User

Word, tool update-alternatives is the function of the management system under the similar function of the symbolic link, the way is to have a similar function of the program, not directly call the program, but with a unified symbolic link to call, as to the symbolic link

Which of the similar function programs is pointed to, is configured and managed by the tool update-alternatives.

It's very abstract, so let's take an example and see what's going on naturally. The Ubuntu system contains a castrated version of the Vim editor,

When we installed a fully functional vim editor, there were 2 vim editors on the system that were similar in function, but note that it

They are not the same program. So what does this have to do with our tool update-alternatives? Originally, Ubuntu system-to-system

The call to the built-in vim is done through a symbolic link called VI, rather than calling vim directly.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/83/64/wKiom1dyGIPT-sA7AACBWFf57Jo865.png "title=" Qq20160628141006.png "alt=" Wkiom1dygipt-sa7aacbwff57jo865.png "/>

From the above output, VI is eventually linked to/usr/bin/vim.tiny, which is the Ubuntu castrated version of Vim.

Yes, the update-alternatives mechanism is a 2-level jump to complete the actual program call. I think we must be curious about this.

How does update-alternatives know which programs have similar functions? And how do they manage them? Let's pass the example of VI

To try to answer these questions. I do not know how to answer these two questions, so only to help the system man, through the man's help

Found a list of two update-alternatives:

/etc/alternatives: There is a second level symbolic link in the directory, pointing to the actual program. There are also files associated with the actual program (such as helping

Help documentation) for symbolic links.

/var/lib/dpkg/alternatives: It is probably the management of similar programs and their associated files (such as help documents) that are stored under the directory.

File.

For the description of the above two directories, it is my inference that we also need to prove the correctness of the inference. Directory/etc/alternatives.

The effect is obvious, you can see the following output through the LS-L command:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/83/64/wKioL1dyKLaBYopxAAG-_-Fuk-4610.png "title=" Qq20160628141006.png "alt=" Wkiol1dyklabyopxaag-_-fuk-4610.png "/>

The file in the Red line box is a symbolic link to a VIM-related help document in addition to a link to vim.tiny.

Next, we validate our inference of the/var/lib/dpkg/alternatives effect and further understand that the directory is

Use. Before installing the full version of Vim, take a look at the file/var/lib/dpkg/alternatives/vi this possible management file:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/83/64/wKioL1dyKnHiqJWEAABmh3sEMC4783.png "title=" Qq20160628152332.png "alt=" Wkiol1dyknhiqjweaabmh3semc4783.png "/>

To the above file, I edited a little bit, based on my understanding added two blank lines, press the blank line we divide the file into 4 parts. First

Part of auto from the Help document know is Update-alternatives operation mode, the second part of the/USR/BIN/VI is the first level;

The 3rd part of each of the two acts of a whole, and found that the first row of each of the two lines and a/etc/alternatives directory of a VIM help text

The file symbol connection has the same name, and the second line corresponds to the actual linked Help document; The first line in part 4th is the program that is eventually linked, and the second

The number of rows from the Help document is a priority, and when there are several similar programs to choose from, the priority determines the program displayed in the

Update-alternatives the location of the list of optional programs given, the higher the priority of the program appears in front. Well, look at us again.

Information about the VI link obtained by update-alternatives--query VI command:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/83/65/wKiom1dyLkGxROreAADqARrRuQM228.png "title=" Qq20160628152243.png "alt=" Wkiom1dylkgxroreaadqarrruqm228.png "/>

It should be concluded that at least update-alternatives--query VI command is in query/var/lib/dpkg/alternatives/vi

Information is available.

Next we install the full version to observe the Update-alternatives related directories and file changes. With the command:

sudo apt-get install vim

To install the full version of Vim. After the installation is complete, first observe the/USR/BIN/VI link to:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/83/65/wKiom1dyMszSRn0sAABaPaGvVRc253.png "title=" Qq20160628161238.png "alt=" Wkiom1dymszsrn0saabapagvvrc253.png "/>

The VI link has been updated and eventually points to/usr/bin/vim.basic, the full version of the VIM program we installed. Again

Check out the/etc/alternatives and/usr/bin directories:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/83/65/wKioL1dyM1zhWP01AANbAwi5gZk304.png "title=" Qq20160628161316.png "alt=" Wkiol1dym1zhwp01aanbawi5gzk304.png "/>

With the full version of the Vim installation also generated a new symbolic link file and a new program file. Finally, take a look at the file

Changes in/var/lib/dpkg/alternatives/vi:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/83/65/wKioL1dyNIbDDznFAAC6BnDLlT8589.png "title=" Qq20160628162451.png "alt=" Wkiol1dynibddznfaac6bndllt8589.png "/>

Looking at the results of the tool comparison, the red part is the new added content after installing the full version of Vim, the function is to add a new selectable program, from the character

Link can be seen, the default is now selected/usr/bin/vim.basic program, the full version of Vim. The full version of Vim can also be seen from above

Priority 30 is higher than 10 of the castrated version of Vim. It seems that our inference should be correct. Actually update-alternatives is not sure which

program function, if you want to do this, the program itself through the configuration interface provided by Update-alternatives to tell

Update-alternatives, that is, update the file under the/var/lib/dpkg/alternatives directory or create a new file under the directory.

You will find the next generation of a new file/var/lib/dpkg/alternatives/vim.

We can come and run the VI command in the end is not the launch of our complete VIM program/usr/bin/vim.basic. Typing at the command line

VI command. Then get the vi PID (process ID) via the PS command, as follows:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/83/66/wKiom1dyPRvS4w6JAAHK7a_EEUA325.png "title=" Qq20160628164618.png "alt=" Wkiom1dyprvs4w6jaahk7a_eeua325.png "/>

You can see that the PID of the VI program is 4971. We can then use the proc file system to view the complete executable program file for pid=4971

Paths, such as:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/83/66/wKiom1dyPZ-RKLFOAAAzNfFzRpc488.png "title=" Qq20160628164630.png "alt=" Wkiom1dypz-rklfoaaaznffzrpc488.png "/>

Learned that it is indeed running our newly installed VIM full version.

Finally, if you want to change the program entry for the VI, you can change it with the update-alternatives--config/--set command. To

The newly generated/var/lib/dpkg/alternatives/vim file should be update-alternatives--install command to complete.

This article is from the "Jimokuangxiangqu" blog, make sure to keep this source http://4594296.blog.51cto.com/4584296/1793674

Debian Alternatives System:update-alternatives

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.