How to install Java Runtime Environment (JRE) on Ubuntu
The Java Runtime Environment (JRE) allows you to run Java applications on your computer. It includes the Java Virtual Machine (JVM), responsible for executing Java code, and a set of libraries and other components necessary for running Java programs.
JRE is provided by both OpenJDK and Oracle. Oracle provides the official version of the JRE, while OpenJDK provides the open-source implementation of the JRE specifications. OpenJDK's JRE is available in apt's default repository, while Oracle's JRE must be manually downloaded and installed. JRE is also included with the Java Developer Kit (JDK). If you only need to run Java programs, you only need to install the JRE.
You can install OpenJDK's JRE by using apt at the terminal. There are also multiple versions available that you can choose from depending on your needs.
Steps to install Java Runtime Environment (JRE) on Ubuntu:
-
Launch terminal.
-
Update apt's package list.
$ sudo apt update [sudo] password for user: Hit:1 http://ports.ubuntu.com/ubuntu-ports kinetic-security InRelease Hit:2 http://us.ports.ubuntu.com/ubuntu-ports kinetic InRelease Hit:3 http://us.ports.ubuntu.com/ubuntu-ports kinetic-updates InRelease Hit:4 http://us.ports.ubuntu.com/ubuntu-ports kinetic-backports InRelease Reading package lists... Done Building dependency tree... Done Reading state information... Done 6 packages can be upgraded. Run 'apt list --upgradable' to see them.
-
Install the default version of JRE for your Ubuntu release.
$ $ sudo apt install --assume-yes default-jre 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 6 not upgraded. Need to get 43.2 MB of archives. After this operation, 179 MB of additional disk space will be used. ##### snipped
-
Check the JRE version to verify the installation.
$ java -version openjdk version "11.0.17" 2022-10-18 OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu2) OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu2, mixed mode)
-
Check other available JRE versions for your Ubuntu release.
$ sudo apt-cache search openjdk | grep "jre\ " openjdk-11-jre - OpenJDK Java runtime, using Hotspot JIT default-jre - Standard Java or Java compatible Runtime openjdk-17-jre - OpenJDK Java runtime, using Hotspot JIT openjdk-18-jre - OpenJDK Java runtime, using Hotspot JIT openjdk-19-jre - OpenJDK Java runtime, using Hotspot JIT openjdk-20-jre - OpenJDK Java runtime, using Hotspot JIT openjdk-8-jre - OpenJDK Java runtime, using Hotspot JIT
-
Install other available JRE versions if necessary.
$ sudo apt install --assume-yes openjdk-20-jre Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: openjdk-20-jre-headless Suggested packages: fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei | fonts-wqy-zenhei The following NEW packages will be installed: openjdk-20-jre openjdk-20-jre-headless 0 upgraded, 2 newly installed, 0 to remove and 6 not upgraded. Need to get 49.4 MB of archives.
-
Set the default JRE version if you have multiple versions installed.
$ sudo update-alternatives --config java There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-20-openjdk-arm64/bin/java 2011 auto mode 1 /usr/lib/jvm/java-11-openjdk-arm64/bin/java 1111 manual mode 2 /usr/lib/jvm/java-20-openjdk-arm64/bin/java 2011 manual mode Press <enter> to keep the current choice[*], or type selection number: 1 update-alternatives: using /usr/lib/jvm/java-11-openjdk-arm64/bin/java to provide /usr/bin/java (java) in manual mode
-
Check if the selected JRE version is now set to default.
$ java --version openjdk 11.0.17 2022-10-18 OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu2) OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu2, mixed mode)