To develop Java applications, you need to install the Java Development Kit (JDK), which includes the tools required to compile and run Java programs. The JDK also comes with the Java Runtime Environment (JRE), which is necessary to execute Java applications. OpenSUSE and SUSE Linux Enterprise Server (SLES) provide a simple way to install OpenJDK, the open-source version of the JDK, via the system package manager.

OpenJDK is readily available in the default repositories for openSUSE and SLES. This makes it the preferred option for users who want to quickly install and maintain multiple versions of JDK. You can search for different versions of OpenJDK through the package manager, install one, and set it as the default. Oracle's JDK is also an option but is not available in the default repositories and requires additional steps for installation.

With the zypper package manager, you can manage different versions of JDK easily. Multiple JDK installations can coexist on your system, and you can choose which version to use as the default. This flexibility is helpful for developers working with different projects that may require specific JDK versions. Below are the steps to install OpenJDK on openSUSE and SLES.

Steps to install Java JDK on openSUSE/SLES using zypper:

  1. Open the terminal.
  2. Update the package list using zypper.
    > 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.
  3. Search for available OpenJDK versions.
    > 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
  4. Install the required JDK version.
    > 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
  5. Verify the installed javac version.
    > javac -version
    javac 17.0.5
  6. Install other JDK version if required.
    > 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.
  7. Set the default javac version if multiple JDKs are installed.
    > 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
  8. Confirm the default javac version.
    > javac -version
    javac 1.8.0_352
Discuss the article:

Comment anonymously. Login not required.