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, CentOS has Java 11 as latest version while the latest version from official Java is Java 19.

Steps to install Java Runtime Environment (JRE) on CentOS ===== Steps to install Java Runtime Environment (JRE) on CentOS & Red Hat: ===== Red Hat:

  1. Launch terminal.
  2. Install OpenJDK JRE from official repository
    [user@centos-host ~]$ sudo yum install java-11-openjdk.x86_64 --assumeyes
    Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
     * base: centos.mirror.myduniahost.com
     * extras: mirror.gi.co.id
     * updates: vpsmurah.jagoanhosting.com
    Resolving Dependencies
    --> Running transaction check
    ---> Package java-11-openjdk.x86_64 1:11.0.16.1.1-1.el7_9 will be installed
    --> Processing Dependency: java-11-openjdk-headless(x86-64) = 1:11.0.16.1.1-1.el7_9 for package: 1:java-11-openjdk-11.0.16.1.1-1.el7_9.x86_64
    --> Running transaction check
    ---> Package java-11-openjdk-headless.x86_64 1:11.0.16.1.1-1.el7_9 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ==========================================================================================
     Package                       Arch        Version                     Repository    Size
    ==========================================================================================
    Installing:
     java-11-openjdk               x86_64      1:11.0.16.1.1-1.el7_9       updates      236 k
    Installing for dependencies:
     java-11-openjdk-headless      x86_64      1:11.0.16.1.1-1.el7_9       updates       39 M
    
    Transaction Summary
    ==========================================================================================
    Install  1 Package (+1 Dependent package)
    
    Total download size: 40 M
    Installed size: 166 M
    Downloading packages:
    (1/2): java-11-openjdk-11.0.16.1.1-1.el7_9.x86_64.rpm              | 236 kB  00:00:00     
    (2/2): java-11-openjdk-headless-11.0.16.1.1-1.el7_9.x86_64.rpm     |  39 MB  00:00:03     
    ------------------------------------------------------------------------------------------
    Total                                                      13 MB/s |  40 MB  00:00:03     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : 1:java-11-openjdk-headless-11.0.16.1.1-1.el7_9.x86_64                  1/2 
      Installing : 1:java-11-openjdk-11.0.16.1.1-1.el7_9.x86_64                           2/2 
      Verifying  : 1:java-11-openjdk-11.0.16.1.1-1.el7_9.x86_64                           1/2 
      Verifying  : 1:java-11-openjdk-headless-11.0.16.1.1-1.el7_9.x86_64                  2/2 
    
    Installed:
      java-11-openjdk.x86_64 1:11.0.16.1.1-1.el7_9                                            
    
    Dependency Installed:
      java-11-openjdk-headless.x86_64 1:11.0.16.1.1-1.el7_9                                   
    
    Complete!
    [user@centos-host ~]$ 
    
  3. Change Java default version accordingly
    [user@centos-host ~]$ sudo alternatives --config java
    
    There is 3 program that provides 'java'.
    
      Selection    Command
    -----------------------------------------------
       1           java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.261-2.6.22.2.el7_8.x86_64/jre/bin/java)
    *  2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.345.b01-1.el7_9.x86_64/jre/bin/java)
     + 3           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.16.1.1-1.el7_9.x86_64/bin/java)
    
    Enter to keep the current selection[+], or type selection number: 
  4. Check JRE version to verify installation.
    [user@centos-host ~]$ java --version
    openjdk 11.0.16.1 2022-08-12 LTS
    OpenJDK Runtime Environment (Red_Hat-11.0.16.1.1-1.el7_9) (build 11.0.16.1+1-LTS)
    OpenJDK 64-Bit Server VM (Red_Hat-11.0.16.1.1-1.el7_9) (build 11.0.16.1+1-LTS, mixed mode, sharing)
    [user@centos-host ~]$ 
    

Steps to install Java Runtime Environment (JRE) on Fedora:

  1. Launch terminal.
  2. Install OpenJDK JRE from official repository.
    [user@fedora-host ~]$ sudo dnf install java-17-openjdk --assumeyes
    Last metadata expiration check: 0:24:39 ago on Mon 31 Oct 2022 09:55:50 AM +08.
    Dependencies resolved.
    ===========================================================================================================
     Package                     Architecture       Version                          Repository           Size
    ===========================================================================================================
    Installing:
     java-17-openjdk             x86_64             1:17.0.4.1.1-1.fc36              updates             229 k
    
    Transaction Summary
    ===========================================================================================================
    Install  1 Package
    
    Total download size: 229 k
    Installed size: 715 k
    Downloading Packages:
    java-17-openjdk-17.0.4.1.1-1.fc36.x86_64.rpm                               278 kB/s | 229 kB     00:00    
    -----------------------------------------------------------------------------------------------------------
    Total                                                                      119 kB/s | 229 kB     00:01     
    Running transaction check
    Transaction check succeeded.
    Running transaction test
    Transaction test succeeded.
    Running transaction
      Preparing        :                                                                                   1/1 
      Installing       : java-17-openjdk-1:17.0.4.1.1-1.fc36.x86_64                                        1/1 
      Running scriptlet: java-17-openjdk-1:17.0.4.1.1-1.fc36.x86_64                                        1/1 
      Verifying        : java-17-openjdk-1:17.0.4.1.1-1.fc36.x86_64                                        1/1 
    
    Installed:
      java-17-openjdk-1:17.0.4.1.1-1.fc36.x86_64                                                               
    
    Complete!
    [user@fedora-host ~]$
  3. Change Java default version accordingly.
    [user@fedora-host ~]$ sudo update-alternatives --config java
    
    There are 2 programs which provide 'java'.
    
      Selection    Command
    -----------------------------------------------
    *+ 1           java-17-openjdk.x86_64 (/usr/lib/jvm/java-17-openjdk-17.0.4.1.1-1.fc36.x86_64/bin/java)
       2           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.16.1.1-1.fc36.x86_64/bin/java)
    
    Enter to keep the current selection[+], or type selection number: 
  4. Check JRE version to verify installation.
    [user@fedora-host ~]$ java --version
    openjdk 17.0.4.1 2022-08-12
    OpenJDK Runtime Environment (Red_Hat-17.0.4.1.1-1.fc36) (build 17.0.4.1+1)
    OpenJDK 64-Bit Server VM (Red_Hat-17.0.4.1.1-1.fc36) (build 17.0.4.1+1, mixed mode, sharing)
    [user@fedora-host ~]$ 
Discuss the article:

Comment anonymously. Login not required.