Let’s see how to install JDK on OpenSuse Linux. For this example we will use Adoptium JDK. Here is Documentation that you can see more detail how to install on OpenSuse and other distributions:
https://adoptium.net/installation/linux/
You can see here the versions which are available for OpenSuse:
https://packages.adoptium.net/ui/native/rpm/opensuse/
According to the documentation to install Adoptium JDK on OpenSuse 15 Leap we need to add first the repository:
zypper ar -f https://packages.adoptium.net/artifactory/rpm/opensuse/$(. /etc/os-release; echo $VERSION_ID)/$(uname -m) adoptium
You need to execute this command with sudo if your user do not have sufficient privileges
The to install specific version for example JDK 17 the command is:
zypper install temurin-17-jdk
Now to check if the java has the version that you expect you can write:
java -version
The you will see response similar to this:
openjdk version "17.0.6" 2023-01-17
OpenJDK Runtime Environment Temurin-17.0.6+10 (build 17.0.6+10)
OpenJDK 64-Bit Server VM Temurin-17.0.6+10 (build 17.0.6+10, mixed mode, sharing)
If you have more then one JDK or JVM and the version is not the one the you expect you can change it with the command:
update-alternatives --config java
The you will see similar to this output and by writing a number we can switch between JDK/JVM versions:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib64/jvm/jre-11-openjdk/bin/java 2105 auto mode
1 /usr/lib64/jvm/jre-11-openjdk/bin/java 2105 manual mode
2 /usr/lib64/jvm/temurin-17-jdk/bin/java 1161 manual mode
Press <enter> to keep the current choice[*], or type selection number:
In this case we can select 2 and press enter:
update-alternatives: using /usr/lib64/jvm/temurin-17-jdk/bin/java to provide /usr/bin/java (java) in manual mode