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)

To run a Java program, a Java Runtime Environment (JRE) is needed to be installed, not to be confused with Java Development Kit (JDK), which is needed only to compile a Java program.

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 Runtime Environment (JRE) 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
    Loading repository data...
    Reading installed packages...
    Resolving package dependencies...
    
    The following 2 NEW packages are going to be installed:
      java-17-openjdk java-17-openjdk-headless
    
    2 new packages to install.
    Overall download size: 38.5 MiB. Already cached: 0 B. After the operation, additional 179.8 MiB will be
    used.
    Continue? [y/n/v/...? shows all options] (y): y
    Retrieving package java-17-openjdk-headless-17.0.4.0-150400.3.3.1.x86_64
                                                                       (1/2),  38.3 MiB (179.3 MiB unpacked)
    Retrieving: java-17-openjdk-headless-17.0.4.0-150400.3.3.1.x86_64.rpm ................[done (6.6 MiB/s)]
    Retrieving package java-17-openjdk-17.0.4.0-150400.3.3.1.x86_64    (2/2), 240.8 KiB (447.5 KiB unpacked)
    Retrieving: java-17-openjdk-17.0.4.0-150400.3.3.1.x86_64.rpm .....................................[done]
    
    Checking for file conflicts: .....................................................................[done]
    update-alternatives: using /usr/lib64/jvm/jre-17-openjdk/bin/java to provide /usr/bin/java (java) in auto mode
    update-alternatives: using /usr/lib64/jvm/jre-17-openjdk to provide /usr/lib64/jvm/jre-openjdk (jre_openjdk) in auto mode
    update-alternatives: using /usr/lib64/jvm/jre-17-openjdk to provide /usr/lib64/jvm/jre-17 (jre_17) in auto mode
    (1/2) Installing: java-17-openjdk-headless-17.0.4.0-150400.3.3.1.x86_64 ..........................[done]
    (2/2) Installing: java-17-openjdk-17.0.4.0-150400.3.3.1.x86_64 ...................................[done]
    Executing %posttrans scripts .....................................................................[done]
    user@suse-host:~> 
  4. Change Java default version accordingly
    user@suse-host:~> sudo update-alternatives --config java
    There are 2 choices for the alternative java (providing /usr/bin/java).
    
      Selection    Path                                    Priority   Status
    ------------------------------------------------------------
    * 0            /usr/lib64/jvm/jre-17-openjdk/bin/java   2705      auto mode
      1            /usr/lib64/jvm/jre-11-openjdk/bin/java   2105      manual mode
      2            /usr/lib64/jvm/jre-17-openjdk/bin/java   2705      manual mode
    
    Press <enter> to keep the current choice[*], or type selection number: 
  5. Check JRE version to verify installation.
    user@suse-host:~> java --version
    openjdk 17.0.4 2022-07-19
    OpenJDK Runtime Environment (build 17.0.4+8-suse-150400.3.3.1-x8664)
    OpenJDK 64-Bit Server VM (build 17.0.4+8-suse-150400.3.3.1-x8664, mixed mode)
    user@suse-host:~> 
    
Discuss the article:

Comment anonymously. Login not required.