Ubuntu update-alternatives

from

Laity size
http://hi.baidu.com/surendaxiao/blog/item/f933f9d13b58a781a0ec9ce4.html


Linux development today, the available software has been very much. So naturally there will be some software functions substantially the same. For example, the same editor, there nvi, vim, emacs, nano, and I said these were only a part. In most cases, such a function similar software is installed on your system, you can use their name to perform. For example, to execute vim, as long as the input at terminal vim and press enter it. However, in some cases we need to call one of these programs with a relatively fixed order. For example, when we write a script, just write the editor, do not want to be as "editor which is" to worry about. Debian provides a mechanism to solve this problem, update-alternatives is used to achieve such a mechanism.

In describing details of the update-alternatives between, let us look at an example already in the system. Open a terminal, the following command:

Herbert Natsu @: ~ $ LS -l / usr / bin / Editor
lrwxrwxrwx the root 24 2004-09-26 08:48. 1 the root / usr / bin / Editor -> / etc / Alternatives / Editor
@ Natsu Herbert: ~ $ LS -l / etc / Alternatives / Editor
lrwxrwxrwx 2004-10-27 16:24. 1 the root 12 is the root / etc / Alternatives / Editor -> / usr / bin / Vim
Herbert Natsu @: ~ $

We see, editor executable command is actually a symbolic link, which points to / etc / alternatives / editor; and / etc / alternatives / editor is also a symbolic link that points to / usr / bin / vim. Thus, when I enter the editor and press Enter to execute vim. The reason to worry about the establishment of such two links in / usr / bin and / etc / alternatives, the characteristic is to achieve the above mentioned: easy script
management system and written procedures.

Here we take a look at the update-alternatives function. Of course, if you think I have not made myself in detail, you can see manpage this command: UPDATE-ALTERNATIVES (8).

Parameters first to introduce the --display. It allows us to see all the optional command a command. Execution

natsu: / Home / Herbert Update #-Alternatives --display Editor
Editor - Status IS Auto.
Link Rate this page Currently Points to / usr / bin / vim
/ bin / ED - priority -100
Slave editor.1.gz: / usr / report this content share /man/man1/ed.1.gz
/ usr / bin / NVI - 19 priority
Slave editor.1.gz: /usr/share/man/man1/nvi.1.gz
/ bin / Nano - priority 40
Slave Editor. 1.gz: /usr/share/man/man1/nano.1.gz
/ usr / bin / Vim - priority 120
Slave editor.1.gz: /usr/share/man/man1/vim.1.gz
/ usr / bin / emacs21 - priority 0
Slave editor.1.gz: / usr / Share /man/man1/emacs.1emacs21.gz
Current `Best 'Version iS / usr / bin / vim.
natsu: / Home / Herbert #

you can see all the commands can be used to link editor on my machine.

Here to talk about --config. This option allows us to choose a command:

natsu: / Home / Herbert Update #---config Editor Alternatives

There are 5 Alternatives Which the Provide `Editor '.

Selection Alternative
-------------- ---------------------------------
. 1 / bin / ED
2 / usr / bin / NVI
. 3 / bin / Nano
+. 4 * / usr / bin / Vim
. 5 / usr / bin / emacs21

Press Enter to Keep The default [*], or type Selection Number:. 4
`The Using / usr / bin / vim 'to the Provide` Editor'.
Natsu: / Home / Herbert #

I did not change it, because I still prefer the vim. Of course, you can choose another program.

Here we will introduce some of the concepts. First, update-alternatives in general by the installation script and postinst such prerm invoked automatically, so that a state where there are two alternative: automatic and manual. The initial state of each alternative is automatic. If the system finds an administrator manually modify the alternative, it automatically becomes the state went from a manual, so the installation script will not update it. If you want an alternative to automatically change back, just run

update-alternatives --auto editor

on it. Did you notice? We talk about a "name." How to write the name of it? This is what we want to introduce a second concept:
General name - which means "public" name similar to a series of functions of the program (including absolute path), such as / usr / bin / editor.
link - This refers to a name / etc / alternative the alternative, such as editor.
alternative - As the name suggests, this is the path to an optional program is located (including absolute path), such as / usr / bin / vim.
- auto, - display and --config with are link. We say third concept is the priority. This is relatively simple, of course, the higher the priority of the program, the better it (in most cases, I do not want to argue) final concept is the master and slave alternative. Think about it, you will be / usr / bin / editor is linked to the vim, but when you execute man editor is emacs see the manpage, you will Zuoheganxiang it? This leads to the concept of the master and slave alternative: when updating the main alternative, will be updated from the alternative.

After saying these four important concept, we introduce the other two options. As for the other. . . . I believe you will see the man page, right?

The first is --install. Its format is:

Update Alternatives --install-Gen Link alt PRI [--slave sgen slink Salt] ...

Gen, Link, alt, said PRI are above us. If you need alternative from, you can use --slave added later. If you add a new set of alternatives to an existing alternative, the order of these alternatives will be added to the alternative group already exists in the
list, and with a new optional command as a new command; otherwise, it will establish a new automated alternative group.

Alas! I joined a wrong alternative. I do not want this alternative of. In this case, the following command can be executed:

Update path-name Alternatives --remove

is a name in the / etc / alternatives in the name which is above the link, and path is an absolute pathname optional program name you want to remove the (rest assured, this only removes the program from the list, and will not really delete the program's executable file from the hard disk). If you remove a program that is being linked from one alternative group and this group is still not become empty, update-alternatives will automatically use one of the other optional programs have priority instead of the original program. If the group becomes empty, then even this alternative set will be removed. If you remove the program are not linked, only information about the program will be removed.

Say you an example. I downloaded the Eclipse, and installed gcj and gij. But I found the GNU java tool is not enough to run Eclipse. I had to go to the Sun's website to download its tools java jdk. Because it is their own installed, I installed them on the / usr / local, so that in the future when you reinstall the Linux system you can still use these programs. So I have to do is use this in java and javac jdk to replace the original system. Execution

natsu: / Home / Herbert # Update the Java-Alternatives --display
. The Java - Status IS Auto
Link Rate this page Currently Points to /usr/local/j2sdk1.4.2_06/bin/java
/usr/bin/gij-wrapper-3.3 - priority 33 is
Slave java.1.gz: /usr/share/man/man1/gij-wrapper-3.3.1.gz
/usr/local/j2sdk1.4.2_06/bin/java - priority 100
slave java.1.gz: /usr/local/j2sdk1.4.2_06/man/man1/java.1
Current `best' version is /usr/local/j2sdk1.4.2_06/bin/java.
natsu:/home/herbert# update-alternatives --display javac
javac - status is auto.
link currently points to /usr/local/j2sdk1.4.2_06/bin/javac
/usr/bin/gcj-wrapper-3.3 - priority 33
slave javah: /usr/bin/gcjh-wrapper-3.3
slave javac.1.gz: /usr/share/man/man1/gcj-wrapper-3.3.1.gz
slave javah.1.gz: /usr/share/man/man1/gcjh-wrapper-3.3.1.gz
/usr/bin/gcj-wrapper-3.4 - priority 33
slave javah: /usr/bin/gcjh-wrapper-3.4
slave javac.1.gz: /usr/share/man/man1/gcj-wrapper-3.4.1.gz
javah.1.gz Slave: /usr/share/man/man1/gcjh-wrapper-3.4.1.gz
/usr/local/j2sdk1.4.2_06/bin/javac - priority 100
Slave the javah: / usr / local / j2sdk1 .4.2_06 / bin / javah
Slave javac.1.gz: /usr/local/j2sdk1.4.2_06/man/man1/javac.1
Slave javah.1.gz: /usr/local/j2sdk1.4.2_06/man/ man1 / javah.1
Current `Best 'Version iS /usr/local/j2sdk1.4.2_06/bin/javac.
natsu: / Home / Herbert #

(you see after I update) you can get about what you want to update alternatives information. I was so update:

update-alternatives --install /usr/bin/javac javac /usr/local/j2sdk1.4.2_06/bin/javac 100 --slave /usr/bin/javah javah /usr/local/j2sdk1.4.2_06/bin/javah --slave /usr/share/man/man1/javac.1.gz javac.1.gz /usr/local/j2sdk1.4.2_06/man/man1/javac.1 --slave /usr/share/man/man1/javah.1.gz javah.1.gz /usr/local/j2sdk1.4.2_06/man/man1/javah.1
update-alternatives --install /usr/bin/java java /usr/local/j2sdk1.4.2_06/bin/java 100 --slave /usr/share/man/man1/java.1.gz java.1.gz /usr/local/j2sdk1.4.2_06/man/man1/java.1


Published 18 original articles · won praise 16 · views 390 000 +

Guess you like

Origin blog.csdn.net/f_zongjian/article/details/7054626
Recommended