1.更新源
sudo apt update
2.升級
sudo apt upgrade -y
3.查看jdk版本
sudo apt-cache search jdk
部分內容顯示如下
default-jdk - Standard Java or Java compatible Development Kit
default-jdk-doc - Standard Java or Java compatible Development Kit (documentation)
openjdk-11-jre-dcevm - Alternative VM for OpenJDK 11 with enhanced class
...
openjdk-17-jre-zero - Alternative JVM for OpenJDK, using Zero
openjdk-17-source - OpenJDK Development Kit (JDK) source files
openjdk-8-dbg - Java runtime based on OpenJDK (debugging symbols)
openjdk-8-demo - Java runtime based on OpenJDK (demos and examples)
openjdk-8-doc - OpenJDK Development Kit (JDK) documentation
openjdk-8-jre - OpenJDK Java runtime, using Hotspot JIT
openjdk-8-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)
openjdk-8-jre-zero - Alternative JVM for OpenJDK, using Zero/Shark
openjdk-8-source - OpenJDK Development Kit (JDK) source files
substance - cross-platform look & feel for Swing applications
substance-doc - cross-platform look & feel for Swing applications - documentation
substance-flamingo - Substance Flamingo plugin
...
4.選擇需要安裝的版本進行安裝,以安裝jdk-8爲例
安裝目錄爲 /usr/lib/jvm
sudo apt install -y openjdk-8-jdk
5.查看java版本
java -version
6.切換不同版本的java
- 通過軟鏈接切換j不同的版本-java
sudo update-alternatives --config java
我的系統顯示如下:
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-18-openjdk-amd64/bin/java 1811 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-18-openjdk-amd64/bin/java 1811 manual mode
* 3 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number:
根據提示鍵入需要的jdk版本。
- 通過軟鏈接切換不同的版本-javac
sudo update-alternatives --config javac
參考:
版权声明:本文为weixin_41661897原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。