You need a Java Development Kit (JDK) to develop and compile Java applications. Installing a JDK will also install the Java Runtime Environment (JRE), which is required to run Java applications.
OpenJDK and Oracle provide JDK that you can install on OpenSUSE and SUSE Linux Enterprise Server (SLES). Oracle's JDK may have some additional features not available in OpenJDK's JDK. Still, it's not available in the default package manager's default repositories and requires a few manual steps. This guide, however, will only cover installing OpenJDK's JDK.
You can install OpenJDK's JDK on OpenSUSE and SLES using zypper at the terminal. You can also install multiple versions of JDKs if required and choose one as the default version.
> sudo zypper refresh [sudo] password for root: Retrieving repository 'Update repository of openSUSE Backports' metadata ...............................[done] Building repository 'Update repository of openSUSE Backports' cache ....................................[done] Retrieving repository 'Non-OSS Repository' metadata ....................................................[done] Building repository 'Non-OSS Repository' cache .........................................................[done] Retrieving repository 'Main Repository' metadata .......................................................[done] Building repository 'Main Repository' cache ............................................................[done] Retrieving repository 'Update repository with updates from SUSE Linux Enterprise 15' metadata ..........[done] Building repository 'Update repository with updates from SUSE Linux Enterprise 15' cache ...............[done] Retrieving repository 'Main Update Repository' metadata ................................................[done] Building repository 'Main Update Repository' cache .....................................................[done] Retrieving repository 'Update Repository (Non-Oss)' metadata ...........................................[done] Building repository 'Update Repository (Non-Oss)' cache ................................................[done] All repositories have been refreshed.
> sudo zypper search openjdk-devel Loading repository data... Reading installed packages... S | Name | Summary | Type --+--------------------------+------------------------------------+-------- | java-1_8_0-openjdk-devel | OpenJDK 8 Development Environment | package | java-9-openjdk-devel | OpenJDK 9 Development Environment | package | java-10-openjdk-devel | OpenJDK 10 Development Environment | package | java-11-openjdk-devel | OpenJDK 11 Development Environment | package | java-17-openjdk-devel | OpenJDK 17 Development Environment | package
> sudo zypper --non-interactive install java-17-openjdk-devel Loading repository data... Reading installed packages... Resolving package dependencies... The following 3 NEW packages are going to be installed: java-17-openjdk java-17-openjdk-devel java-17-openjdk-headless 3 new packages to install. Overall download size: 41.9 MiB. Already cached: 0 B. After the operation, additional 188.2 MiB will be used. ##### snipped
> javac -version javac 17.0.5
> sudo zypper --non-interactive install java-1_8_0-openjdk-devel Loading repository data... Reading installed packages... Resolving package dependencies... The following 4 NEW packages are going to be installed: java-1_8_0-openjdk java-1_8_0-openjdk-devel java-1_8_0-openjdk-headless lksctp-tools 4 new packages to install. Overall download size: 68.8 MiB. Already cached: 0 B. After the operation, additional 115.1 MiB will be used.
> sudo update-alternatives --config javac There are 2 choices for the alternative javac (providing /usr/bin/javac). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib64/jvm/java-17-openjdk/bin/javac 2705 auto mode 1 /usr/lib64/jvm/java-1.8.0-openjdk/bin/javac 1805 manual mode 2 /usr/lib64/jvm/java-17-openjdk/bin/javac 2705 manual mode Press <enter> to keep the current choice[*], or type selection number: 1 update-alternatives: using /usr/lib64/jvm/java-1.8.0-openjdk/bin/javac to provide /usr/bin/javac (javac) in manual mode
> javac -version javac 1.8.0_352
Comment anonymously. Login not required.