How to install Java runtime on Linux

Last updated on September 9, 2020 by Dan Nanni

Question: I want to run a Java application on my Linux. For that, I need to set up Java Runtime Environment (JRE). How can I install Java Runtime on [insert your Linux distro]?

Java Runtime Environment (JRE) or Java Runtime is a minimal set of Java SDK, which allows one to run Java applications. JRE consists of Java Virtual Machine (JVM), libraries, and other supporting components. If you want to run a complied Java application, you do not have to install a full-featured Java development kit, but just need JRE installed.

There are two choices for setting up JRE on Linux: use either Oracle JRE or OpenJDK JRE (open source implementation of the Java Platform). Choose either one you prefer, as described in the following.

Install Oracle JRE on Linux

Go to Oracle website, and click on JRE Download link.

On the next page, accept Oracle license agreement. Then download a file according to your Linux system:

To install Oracle JRE on RPM-based Linux:

$ sudo rpm -ivh jre1.7.0_45-linux-<arch>.rpm

To install Oracle JRE on non RPM-based Linux:

$ sudo mkdir -p /usr/java
$ sudo tar xvfvz jre1.7.0_45-linux-<arch>.tar.gz -C /usr/java

After installation, set the following environment variables in ~/.bashrc

JAVA_HOME=/usr/java/jre1.7.0_45
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin

Install OpenJDK Java Runtime on Linux

To install OpenJDK Java Runtime on Debian, Ubuntu or Linux Mint:

$ sudo apt-get install openjdk-7-jre

To install OpenJDK Java Runtime on Fedora, CentOS or RHEL:

$ sudo yum install java-1.7.0-openjdk

After installation, set JAVA_HOME environment variable in ~/.bashrc

JAVA_HOME=/etc/alternative/jre

If you cannot find /etc/alternative/jre folder, set JAVA_HOME to an alternative path (e.g., /usr/lib/jvm/default-java).

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal (Credit Card) or Bitcoin (1M161JGAkz3oaHNvTiPFjNYkeABox8rb4g).

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean