The update-alternatives command implements jdk switching under ubuntu

Note:
If my system has java 1.6 installed, I want to install java 1.7, but I don't want to uninstall java 1.6. You can switch processes between multiple java versions through update-alternatives –config. update-alternatives is a script used to switch between multiple commands of the same type. In debian, it can be installed by apt-get install dpkg.

Before explaining the detailed usage of update-alternatives, let's take a look at the examples already in the system. Open a terminal and execute the following command:
# ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 2011-03-12 15:20 /usr/bin/java -> /etc/alternatives/java

# ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 40 2011-03-12 15:20 /etc/alternatives/java -> /usr/lib/jvm/java-6-openjdk/jre/bin/java
java This executable command is actually a link to /etc/alternatives/java. And this is also a link, pointing to /usr/lib/jvm/java-6-openjdk/jre/bin/java, which is the final executable file. The reason for establishing such two links is to facilitate the writing of script programs and the management of the system.

Grammar:
Temporarily empty! ! !

Example:
1. The display parameter lists all optional commands of a command

# update-alternatives --display java

 
2. The config parameter is used to select a link value for a command, which is equivalent to switching among the available values.

# update-alternatives --config java //There are 3 candidates that can be used to replace java (provides /usr/bin/java)   select path priority status ----------------- ------------------------------------------- 0 / usr / lib / jvm / java - 6 - openjdk / jre / bin / java       1061 automatic mode * 1 /home/wuekzhu/download/jdk1.6.0_23/bin/java 1 manual    mode _ _ _ _ _ _ _ _ _ _ _ _2 / usr / lib / jvm / java - 6 - openjdk / jre / bin / java       1061 manual mode

 
3. The install parameter is used to add the link value of a command, which is equivalent to adding an available value, where slave is very useful.

# update-alternatives –install /usr/bin/java java /usr/local/jre1.6.0_20/bin/javac 100  # update-alternatives –install /usr/bin/java java /usr/local/jre1.6.0_20/bin/javac 100 –slave /usr/bin/javac javac /usr/local/jre1.6.0_20/bin/javac  

 
4. The remove parameter is used to delete the link value of a command, and the attached slave will also be deleted together.

# update-alternatives –remove java /usr/local/jre1.6.0_20/bin/java  

 
Of course, if you want to use java, you still have to add java to the environment variable as follows.
# vim /etc/profile //Add the following at the end
JAVA_HOME=/usr/local/jdk1.5.0_22
CLASSPATH=.:$JAVA_HOME/lib/tools.jar
PATH=$PATH: $JAVA_HOME/bin
export PATH=$PATH :$JAVA_HOME/bin
export JAVA_HOME CLASSPATH PATH
If you want to switch between multiple versions of java through update-alternatives, simply use update-alternatives –config java to select the java version we want!

Addendum:
Addendum 1.The path setting in /etc/profile can choose to override or not override the /usr/bin/java command.
If I set profile like this, jdk1.5 is used:
#set java environment
JAVA_HOME=/home/wuekzhu/download/jdk1.5.0_22
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$ PATH
If I set profile like this, then /usr/bin/java -> /etc/alternatives/java is used:
#set java environment
JAVA_HOME=/home/wuekzhu/download/jdk1.5.0_22
CLASSPATH=.:$JAVA_HOME/lib /tools.jar
PATH=$PATH: $JAVA_HOME/bin

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326583455&siteId=291194637