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...

15 Responses

  1. dgrb says:

    “JAVA is necessary to run most of the applications in Linux and windows machine.”

    No, it isn’t.

  2. Eemil says:

    Thanks. A question: What other purposes are there for using Java these days except development?
    Some corrections:
    1. You should not edit your user’s local .bashrc using sudo. It belongs to your user, not the system.
    2. You should not need to add java binaries to the path. They are already placed there by most distros, since they live in /usr/bin.
    3. To change java version that is run when you type java, you can use:
    sudo update-alternatives –config java
    No need to use $PATH changing.

  3. Ratnesh says:

    I am trying to install 1.8 version.

    I changed this line
    PATH=$PATH:$HOME/bin:JAVA_HOME:JRE_HOME
    to
    PATH=$HOME/bin:$JAVA_HOME:$JRE_HOME:$PATH

    Previously it is giving old java version only as it will detect old java binary first because of $PATH is defined at starting.
    After changing as per second line it is now working and able to detect 1.8 version in java and javac.

  4. saravana says:

    concise and beautiful

  5. cesar says:

    Thanks!! te pasaste viejo.

  6. Raghavabhargav says:

    i’m new to Linux it was so useful i was searching around thanks

  7. John Bestevaar says:

    Hi Magesh
    Your methodology is very good but your English is a little odd for non-coder like me, which is why i am asking these questions.
    In method 2 open jdk you do not give any instructions or clues for testing or checking the install.?
    After my install command : echo $JAVA_HOME did not return anything.
    Command: java -version , returns
    java version “1.7.0_79”
    OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu0.14.04.2)
    OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
    Can i assume all is OK or do i need to do more?
    Regards JohnB

  8. KTEC says:

    IT WAS VERY HELPFULL……THANKS ALOT.

  9. Ashraf says:

    I have CentOS 7 installed and whenever I run the command
    yum search java | grep openjdk

    I get only openjdk 1.6 & 1.7 not 1.8

    yum search java | grep openjdk
    java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
    java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
    java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
    java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
    java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
    java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
    java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
    java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
    java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
    java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without
    java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
    java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle

    What repo you are using to get 1.8 in the list?

  10. so useful…you have spoken so simple and fluent… nice job

  1. January 15, 2016

    […] Широко распространены два компилятора для JAVA:Oracle (Sun) Java JREJAVA ( OpenJDK ) 6 / 7 / 8 […]

Leave a Reply

Your email address will not be published. Required fields are marked *