檢查系統上可以用版本:
sudo dnf update
sudo dnf search openjdk
可以看到有 1.8.0, openJDK 11, 17, 19
安裝最後一版:
sudo dnf install java-latest-openjdk java-latest-openjdk-devel
輸出結果:
Installed: copy-jdk-configs-4.0-2.el8.noarch java-latest-openjdk-1:19.0.2.0.7-1.rolling.el8.x86_64 java-latest-openjdk-devel-1:19.0.2.0.7-1.rolling.el8.x86_64 java-latest-openjdk-headless-1:19.0.2.0.7-1.rolling.el8.x86_64 javapackages-filesystem-5.3.0-2.module+el8.3.0+125+5da1ae29.noarch lksctp-tools-1.0.18-3.el8.x86_64 ttmkfdir-3.0.9-54.el8.x86_64 tzdata-java-2022g-1.el8.noarch xorg-x11-fonts-Type1-7.5-19.el8.noarch Complete!
檢查版本號碼:
java -version
如果你有需要切換多個 java 版本,參考看看:
Manage Java Versions
If you are using multiple Java versions in your project, then you can easily switch between them using the following command:
alternatives --config java
You will be asked to set the default Java versions as shown below:
There are 3 programs which provide 'java'. Selection Command ----------------------------------------------- 1 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.13.0.8-1.el8_4.x86_64/bin/java) 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.el8_4.x86_64/jre/bin/java) *+ 3 /usr/java/jdk-17.0.1/bin/java Enter to keep the current selection[+], or type selection number: 2
Select your preferred option and hit Enter to set the default Java version.
Next, verify your current Java version using the following command:
java -version
Sample output:
openjdk version "1.8.0_312" OpenJDK Runtime Environment (build 1.8.0_312-b07) OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)