How To Install JAVA (OpenJDK) 7/8/10/11 On Linux?

JAVA is necessary to run certain applications in Linux and windows machine.

JAVA comes with two packages (JDK & JRE).

JDK stands for (Java Development Kit) which helps developers for developing, debugging, and monitoring Java applications.

JRE stands for (Java Runtime Environment) which deploys Java applications on servers.

It includes tools for JVM monitoring and tools commonly required for server applications.

Many of us needed only JRE, so make sure you have installed JRE not for JDE.

In this article we are going to explain how to install OpenJDK in Linux distributions such as RHEL, CentOS, Fedora, Ubuntu, Debian, Mint, openSUSE & Arch Linux based systems.

1) How To Find And Install OpenJDK/JRE On Arch Linux Systems?

Arch Linux is a rolling release distribution. Hence, it’s shipped with latest OpenJKD package. Use the below commands to find available OpenJDK package on Arch Linux based distributions.

$ pacman -Ss java | grep openjdk

extra/jdk-openjdk 11.0.3.u4-1
extra/jdk10-openjdk 10.0.2.u13-1
extra/jdk7-openjdk 7.u171_2.6.13-1
extra/jdk8-openjdk 8.u212-1
extra/jre-openjdk 11.0.3.u4-1
extra/jre-openjdk-headless 11.0.3.u4-1
extra/jre10-openjdk 10.0.2.u13-1
extra/jre10-openjdk-headless 10.0.2.u13-1
extra/jre7-openjdk 7.u171_2.6.13-1
extra/jre7-openjdk-headless 7.u171_2.6.13-1
extra/jre8-openjdk 8.u212-1 [installed]
extra/jre8-openjdk-headless 8.u212-1 [installed]

Run the following command to install JRE 10 (Java Runtime Environment).

$ sudo pacman -Syu jre10-openjdk

Run the following command to install JDK 10 (Java Development Kit).

$ sudo pacman -Syu jdk10-openjdk

2) How To Find And Install OpenJDK/JRE On RHEL7/CentOS7 Systems?

Redhat 7 based distributions also, having latest OpenJKD & JRE packages in their official repository. Use the below commands to find available OpenJDK package on Redhat 7 based distributions.

$ yum search java | grep openjdk

java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without
java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment 8
java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment 8
java-1.8.0-openjdk-headless.x86_64 : OpenJDK Headless Runtime Environment 8
java-1.8.0-openjdk-headless-debug.x86_64 : OpenJDK Runtime Environment with full
java-11-openjdk.x86_64 : OpenJDK Runtime Environment 11
java-11-openjdk-devel.x86_64 : OpenJDK Development Environment 11
java-11-openjdk-headless.x86_64 : OpenJDK Headless Runtime Environment 11

Run the following command to install JRE 11 (Java Runtime Environment).

$ sudo yum install java-11-openjdk-headless.x86_64

Run the following command to install JDK 11 (Java Development Kit).

$ sudo yum install java-11-openjdk-devel.x86_64

3) How To Find And Install OpenJDK/JRE On Ubuntu/Debian Systems?

Debian based systems also shipping with latest OpenJKD & JRE packages in their official repository. Use the below commands to find available OpenJDK package on Debian based distributions.

$ apt-cache search java | grep openjdk
openjdk-11-jdk - OpenJDK Development Kit (JDK)
openjdk-11-jdk-headless - OpenJDK Development Kit (JDK) (headless)
openjdk-11-jre - OpenJDK Java runtime, using Hotspot JIT
openjdk-11-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)
openjdk-8-jdk - OpenJDK Development Kit (JDK)
openjdk-8-jdk-headless - OpenJDK Development Kit (JDK) (headless)
openjdk-8-jre - OpenJDK Java runtime, using Hotspot JIT
openjdk-8-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)

Run the following command to install JRE 8 (Java Runtime Environment).

$ sudo apt install openjdk-8-jre-headless

Run the following command to install JDK 8 (Java Development Kit).

$ sudo apt install openjdk-8-jdk-headless

4) How To Find And Install OpenJDK/JRE On Fedora Systems?

Fedora systems also shipping with latest OpenJKD & JRE packages in their official repository. Use the below commands to find available OpenJDK package on Fedora system.

$ dnf search java | grep openjdk

5) How To Find And Install OpenJDK/JRE On openSUSE Systems?

Use the below commands to find available OpenJDK package on openSUSE system.

$ zypper search java | grep openjdk

6) How To Setup Up JAVA Environment Variables On Linux?

We should Setup JAVA Environment Variables for java because all the java based application uses environment variables to work.

Open your .bashrc file and add the below lines to end of the file. Make sure you need to mention your path instead of us, then Save and exit.

$ sudo nano .bashrc
JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64/bin/java"
JRE_HOME="/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java"
PATH=$PATH:$HOME/bin:JAVA_HOME:JRE_HOME

After saving .bashrc file, run the following command to make it work.

$ sudo source ~/.bashrc

Now you can check the environment variables using below commands. Its clearly fetch the path of jdk and jre home.

$ echo $JAVA_HOME
/usr/lib/jvm/java-7-openjdk-amd64/bin/java

$ echo $JRE_HOME
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java

Enjoy…)

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...

%d bloggers like this: