修改CentOS7預設JDK
阿新 • • 發佈:2018-12-23
CentOS7預設JDK是OpenJDK1.8.*,即使配置了JDK輸入java -version也是如下資訊:
[[email protected] ~]# java -version openjdk version "1.8.0_161" OpenJDK Runtime Environment (build 1.8.0_161-b14) OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
乍一看是1.8.0_161
沒錯,可惜他是openjdk,而我們的應用通常都執行在Oracle JDK中,於是此時就需要使用alternatives
alternatives --install /usr/bin/java java /usr/local/java/jdk1.8.0_161/bin/java 3 alternatives --install /usr/bin/javac javac /usr/local/java/jdk1.8.0_161/bin/javac 3
然後執行下面的命令進行設定:
alternatives --config java
共有 3 個提供“java”的程式。 選項 命令 ----------------------------------------------- 1 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.171-2.6.13.2.el7.x86_64/jre/bin/java) *+ 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64/jre/bin/java) 3 /usr/local/java/jdk1.8.0_161/bin/java 按 Enter 保留當前選項[+],或者鍵入選項編號:3