Update-alternatives is a tool dedicated to maintaining system command links in Linux systems, which makes it easy to set which command to use by default, which software version, for example, we have both open jdk and Sun JDK Two versions installed in the system. And we want the system to use the sun JDK by default, what should we do? Through the update-alternatives can be very convenient to achieve.
To view the options for this command according to the update-alternatives command
[Email protected] ~]$ update-alternatives
Alternatives (standby) version 1.3.61-Copyright (C) 2001 Red Hat Corp.
The software may be freely re-released under the GNU Public License terms.
Usage: Alternatives--install < links > < name > < path > < priority >
[--initscript < services;]
[--slave < links > < name > < path >]*
Alternatives--remove < name > < path >
Alternatives--auto < name >
Alternatives--config < name >
Alternatives--display < name >
Alternatives--set < name > < path >
Alternatives--list
Common options:--verbose--test--help--usage--version
--altdir < directories >--admindir < directories >
Install option
The function of the Install option is to add a new set of system command links, using the following syntax:
Update-alternatives--install Link name path priority [--slave link name path] ...
Link for the system in the same function of the software's public link directory, such as/usr/bin/java (need absolute directory); The name is the command-link, such as Java, where you want to use the new command, the directory where the new software is located, and priority, which is higher than the current value when the command link already exists, because when alternative is in Auto mode, The system by default enables the link to priority high; --slave is from alternative.
Alternative has two modes: auto and manual, which are auto mode by default, because in most cases update-alternatives commands are called by Postinst (configure) or prerm (install), If you change it to manual, the installation script will not update it.
For example:
Update-alternatives--install/usr/bin/java java/usr/local/lib/java/jdk1.7.0_67 17067
#/usr/bin/java The path where Java link resides
# Java creates a link name
#/usr/local/lib/java/jdk1.7.0_67 the path to which the Java link is pointing
# 17067 priority based on version number (change priority needs to be greater than current) version higher priority
Remove option
The Remove option function is to remove a alternative and related from alternative, using the syntax for
Update-alternatives--remove name Path
Where name and path are consistent with the install, if there are other links in the deleted link Group, the system will automatically select a priority link from the other to be the default link.
Update-alternatives--remove java/usr/local/lib/java/jdk1.7.0_67
Auto option
The auto option is used to modify the mode of the command with the following syntax:
Update-alternatives--auto Name
# only two auto and manual modes, default to Auto mode
Config option
The config option function selects one as the system default for the existing command link, using the syntax for:
Update-alternatives--config Name
[Email protected] yxkong]# update-alternatives--config java
There are a total of 2 programs that provide "Java".
Options command
-----------------------------------------------
*+ 1/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.51-2.4.5.5.el7.x86_64/jre/bin/java
2/usr/local/lib/java/jdk1.7.0_67/bin/java
Press Enter to leave the current option [+], or type an option number: 2
Here is the focus of the configuration version, when there are multiple versions of the system, you can set the default version by this command, similar to the default program
Display Options
The display option's function is to view all the information for a command link group, including the linked mode (auto or manual), link priority value, all available link commands, and so on. Use syntax:
Update-alternatives--display Name
Where name is the command link name, such as Java
[Email protected] ~]$ update-alternatives--display java
Java-the state is manual.
Link current point to/usr/local/lib/java/jdk1.7.0_67/bin/java
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.51-2.4.5.5.el7.x86_64/jre/bin/java-Priority 170051
....
The current "best" version is/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.51-2.4.5.5.el7.x86_64/jre/bin/java.
Principle Analysis
Let's see the trail.
[Email protected] ~]$ ls-l/usr/bin/java #该链接link到了/etc/alternatives/java
lrwxrwxrwx. 1 root root 22 September 12:28/usr/bin/java-/etc/alternatives/java
[Email protected] ~]$ ls-l/etc/alternatives/java #链接到了/usr/local/lib/java/jdk1.7.0_67/bin/java
lrwxrwxrwx. 1 root root 40 September 12:28/etc/alternatives/java-/usr/local/lib/java/jdk1.7.0_67/bin/java
Java, the executable command is actually a link, pointing to the/etc/alternatives/java. And this is a link to the/usr/local/lib/java/jdk1.7.0_67/bin/java, which is the final executable file. Such two links are created to facilitate scripting and system management.
Transferred from: http://www.5ycode.com/article/59.html
Centos/linux alternatives and update-alternatives and software version switching