Java is a programming language having almost similar syntax to C++, intended to have minimum dependencies and let the developer write once, run anywhere (WORA)

Java Development Kit (JDK) is needed by developer to compile a Java program and to be executed with Java Runtime Environment (JRE) installed on top of OS.

Latest Java version offered by official repository may differ depending on distribution you are having. At the point of this article is written, OpenSUSE has Java 17 as latest version while the latest version from official Java is Java 19.

Java 11 is being installed in OpenSUSE by default

Steps to install Java Development Kit (JDK) on openSUSE and SLES:

  1. Launch terminal.
  2. Fetch latest package list.
    user@suse-host:~> sudo zypper refresh
    [sudo] password for root: 
    Repository 'openSUSE-Leap-15.4-1' is up to date.                                                        
    Repository 'Update repository of openSUSE Backports' is up to date.                                     
    Repository 'Non-OSS Repository' is up to date.                                                          
    Repository 'Main Repository' is up to date.                                                             
    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]
    Repository 'Update Repository (Non-Oss)' is up to date.                                                 
    All repositories have been refreshed.
    user@suse-host:~> 
  3. Install OpenJDK JRE.
    user@suse-host:~> sudo zypper --non-interactive install java-17-openjdk-devel
    [sudo] password for root: 
    Loading repository data...
    Reading installed packages...
    Resolving package dependencies...
    
    The following NEW package is going to be installed:
      java-17-openjdk-devel
    
    1 new package to install.
    Overall download size: 4.8 MiB. Already cached: 0 B. After the operation, additional 8.8 MiB will be
    used.
    Continue? [y/n/v/...? shows all options] (y): y
    Retrieving package java-17-openjdk-devel-17.0.4.0-150400.3.3.1.x86_64
                                                                       (1/1),   4.8 MiB (  8.8 MiB unpacked)
    Retrieving: java-17-openjdk-devel-17.0.4.0-150400.3.3.1.x86_64.rpm ...................[done (4.0 MiB/s)]
    
    Checking for file conflicts: .....................................................................[done]
    update-alternatives: using /usr/lib64/jvm/java-17-openjdk/bin/javac to provide /usr/bin/javac (javac) in auto mode
    update-alternatives: using /usr/lib64/jvm/java-17-openjdk to provide /usr/lib64/jvm/java-openjdk (java_sdk_openjdk) in auto mode
    update-alternatives: using /usr/lib64/jvm/java-17-openjdk to provide /usr/lib64/jvm/java-17 (java_sdk_17) in auto mode
    (1/1) Installing: java-17-openjdk-devel-17.0.4.0-150400.3.3.1.x86_64 .............................[done]
    user@suse-host:~> 
  4. Change Java default version accordingly
    user@suse-host:~> 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-11-openjdk/bin/javac   2105      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:
  5. Check JRE version to verify installation.
    user@suse-host:~> javac --version
    javac 17.0.4
    user@suse-host:~> 
Discuss the article:

Comment anonymously. Login not required.