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.

Ubuntu provides multiple OpenJDK's Java Runtime Environment in their default apt repository that you can choose to install. There's a default JRE version set for each Ubuntu version, and you can also install multiple JREs on your system if required.

Steps to install only Java Runtime Environment (JRE) on Ubuntu:

  1. Launch terminal.
  2. Fetch the latest package list.
    $ sudo apt update
  3. Install the desired version of OpenJDK JRE.
    user@ubuntu-host:~$ sudo apt install default-jre -y
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    The following additional packages will be installed:
      ca-certificates-java default-jre-headless fonts-dejavu-extra java-common libatk-wrapper-java
      libatk-wrapper-java-jni openjdk-11-jre openjdk-11-jre-headless
    Suggested packages:
      fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei | fonts-wqy-zenhei
    The following NEW packages will be installed:
      ca-certificates-java default-jre default-jre-headless fonts-dejavu-extra java-common
      libatk-wrapper-java libatk-wrapper-java-jni openjdk-11-jre openjdk-11-jre-headless
    0 upgraded, 9 newly installed, 0 to remove and 178 not upgraded.
    Need to get 43.9 MB of archives.
    After this operation, 180 MB of additional disk space will be used.
    Get:1 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 java-common all 0.72build2 [6,782 B]
    Get:2 http://us.archive.ubuntu.com/ubuntu jammy-updates/main amd64 openjdk-11-jre-headless amd64 11.0.16+8-0ubuntu1~22.04 [41.5 MB]
    ##### snipped 
    Processing triggers for man-db (2.10.2-1) ...
    Processing triggers for ca-certificates (20211016) ...
    Updating certificates in /etc/ssl/certs...
    0 added, 0 removed; done.
    Running hooks in /etc/ca-certificates/update.d...
    
    done.
    done.
    user@ubuntu-host:~$ 
  4. Check the JRE version to verify the installation.
    user@ubuntu-host:~$ java -version
    openjdk version "11.0.16" 2022-07-19
    OpenJDK Runtime Environment (build 11.0.16+8-post-Ubuntu-0ubuntu122.04)
    OpenJDK 64-Bit Server VM (build 11.0.16+8-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)
    user@ubuntu-host:~$ 
  5. The default version can be changed if there is multiple versions of JRE was installed.
    $ sudo update-alternatives --config java

Discuss the article:

Comment anonymously. Login not required.