Use alternatives to switch the jdk version of red hat linux



That is to say, the jdk of the system is libgcj hosted by alternatives, and then I tracked it and found that there are several JDK directories available on the server, so now my task is to switch the jdk of alternatives so that it can point to the available JDK The original jdk.

I forgot to introduce gcj, GNU Compiler for Java, which is an open source java compiler of GNU. The specific content can be searched on the Internet.

So I searched on the Internet and solved this problem. Step

1 . First add available JDK to alternatives:

[root@eric-laptop sbin]# ./alternatives --install /usr/bin/java java /usr/share/jdk1.6.XXXX/bin/java 300
[root @eric-laptop sbin]# ./alternatives --install /usr/bin/javac javac /usr/share/jdk1.6.XXXX/bin/javac 300

2. Then display the jdk list available in alternatives

[root@eric -laptop sbin]# ./alternatives --display java
java - status is manual.
link currently points to /usr/share/java/libgcj-java-placeholder.sh
/usr/share/java/libgcj-java-placeholder.sh - priority 100
slave rmiregistry: /usr/bin/grmiregistry
slave rmiregistry.1.gz: /usr/share/man/man1/grmiregistry.1.gz
/usr/share/jdk1.6.XXXX/bin/java - priority 300
slave rmiregistry: (null)
slave rmiregistry.1.gz: (null)
Current `best' version is /usr/share/java/libgcj-java-placeholder.sh.

[root@eric-laptop sbin]# ./alternatives --display javac

javac - status is auto.
link currently points to /usr/share/java/libgcj-javac-placeholder.sh
/usr/share/java/libgcj-javac-placeholder.sh - priority 100
slave jar: /usr/bin/gjar
slave rmic: /usr/bin/grmic
slave jar.1.gz: /usr/share/man/man1/gjar.1.gz
slave rmic.1.gz: /usr/share/man/man1/grmic.1.gz
/usr/share/jdk1.6.XXXX/bin/javac - priority 300
slave jar: (null
) slave rmic: (null) slave
jar.1.gz: (null)
slave rmic.1.gz: (null)
Current `best' version is /usr/share/java/libgcj-javac-placeholder.sh.

3. After confirming that a useful JDK has been added to alternatives, start configuring alternatives
[root@eric-laptop sbin]# ./alternatives --config java

There are 2 programs which provide 'java'.

  Selection Command
---------------------------------- -------------
*+ 1 /usr/share/java/libgcj-java-placeholder.sh
   2 /home/webspher/jdk1.6.XXXX/bin/java
Select 2 at this time It can be changed to a new java. The

same operation [root@eric-laptop sbin]# ./alternatives --config javac



After the operation, you can check the java version

java -version can be used normally

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326530302&siteId=291194637