Referring to Ask Ubuntu question How to set JAVA_HOME for OpenJDK?,

How to install Open JDK (Java developement kit) in Ubuntu (Linux)?

  1. Open Terminal from Application Dash or press Ctrl+Alt+T

  2. Update repository:

    sudo add-apt-repository ppa:openjdk-r/ppa  # only Ubuntu 17.4 and earlier
    sudo apt update
    
  3. Optional: To search available distributions of openjdk, use the following command:

    apt search openjdk
    
  4. Install the appropriate version with the following command:

    sudo apt install openjdk-8-jdk
    sudo apt install openjdk-8-source #this is optional, the jdk source code
    
  5. For JAVA_HOME (Environment Variable) type command as shown below, in "Terminal" using your installation path...

    export JAVA_HOME=/usr/lib/jvm/java-8-openjdk
    

    (Note: /usr/lib/jvm/java-8-openjdk is symbolically used here just for demostration. You should use your path as per your installation.)

  6. For PATH (Environment Variable) type command as shown below, in Terminal:

    export PATH=$PATH:$JAVA_HOME/bin

  7. To check your installation:

    java -version

Answer from Dhaval Shah on Stack Overflow
🌐
Oracle
docs.oracle.com › en › java › javase › 22 › install › installation-jdk-linux-platforms.html
Installation of the JDK on Linux Platforms
March 14, 2024 - The following table lists the differences: Table 3-1 Difference between Generic Linux and OL platforms ... Access Java SE Downloads page and click Accept License Agreement. Under the Download menu, click the Download link corresponding your requirement. The following table lists the options ...
🌐
OpenJDK
openjdk.org › install
OpenJDK: Download and install
As an example, the archives for JDK 13 may be found on jdk.java.net/13 and may be extracted on the command line using · $ tar xvf openjdk-13*_bin.tar.gz · or · $ unzip openjdk-13*_bin.zip · depending on the archive type. On the command line, type: $ sudo apt-get install openjdk-8-jre ·
🌐
Oracle
oracle.com › java › technologies › downloads
Download the Latest Java LTS Free
Subsequent JDK 25 updates will be licensed under the Java SE OTN License (OTN) and production use beyond the limited free grants of the OTN license will require a fee. Linux · macOS · Windows · Documentation Download · Online Documentation · Installation Instructions ·
🌐
Oracle
java.com › en › download › help › linux_x64_install.html
Linux 64-bit installation instructions for Java
Use these instructions to download and install the Java Runtime Environment (JRE) for Linux x64.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › installation guide › how-to-install-jdk-in-linux
How to Install JDK in Linux? - GeeksforGeeks
July 23, 2025 - sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-15.0.2/bin/java 1
Top answer
1 of 4
11

You can install and stay up to date with the latest Oracle Java 7 and all you have to do is manually add the PPA repository to the Software Sources.

From http://www.webupd8.org/2012/06/how-to-install-oracle-java-7-in-debian.html:

su -
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a     /etc/apt/sources.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
apt-get update
apt-get install oracle-java7-installer
exit

For Ubuntu, http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html. With this, I've managed to installed JDK on my ubuntu server.

2 of 4
4

Step 1: Open Applicaction>> Accessories>> Terminal

Step 2: Type commandline as below...

  sudo apt-get install openjdk-6-jdk

Step 3: Type commandline as below...

  apt-cache search jdk

(Note: openjdk-6-jdk is symbolically used here you can choose jdk version as per your requirment.)

How to set "Environment Variables" for "Open jdk" in Ubuntu(Linux)?

Step 4: For "JAVA_HOME" (Environment Variable) type command as shown below, in "Terminal" using your installation path...

  export JAVA_HOME=/usr/lib/jvm/java-6-openjdk

(Note: "/usr/lib/jvm/java-6-openjdk" is symbolically used here just for demostration you should use your path as per your installation.)

Step 5: For "PATH" (Environment Variable) type command as shown below, in "Terminal" using your installation path...

  export PATH=/usr/lib/jvm/java-6-openjdk/bin

(Note: "/usr/lib/jvm/java-6-openjdk" is symbolically used here just for demostration you should use your path as per your installation.)

Step 6: Check for "open jdk" installation, just type command in "Terminal" as shown below java

🌐
GeeksforGeeks
geeksforgeeks.org › java › download-and-install-jdk-on-windows-mac-and-linux
Download and Install JDK on Windows, Mac and Linux - GeeksforGeeks
April 4, 2026 - C:\Program Files\Java\jdk-{YOUR_JDK_VERSION}. Click on OK => OK => OK. ... Follow the steps below to install the Java software Development Kit on a Linux environment.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-install-java-with-apt-on-ubuntu-22-04
How to Install Java with Apt on Ubuntu (JRE & JDK) | DigitalOcean
February 2, 2026 - In this case, you would need Oracle JDK 11.0.13. Your version number may vary depending on when you’re installing the software. You don’t need to download anything from this page; you’ll download the installation script through apt shortly. Next, visit the Archive Downloads and locate the version that matches the one you need. From this list, choose the Linux x64 compressed archive .tar.gz package:
🌐
Azul Systems
azul.com › home › azul downloads
Java 8, 11, 17, 21, 25 Download for Linux, Windows and macOS
May 7, 2026 - Click here to download the Azul Zulu Builds of OpenJDK for Java 8, 11, 17, 21, 25 for Linux, Windows and macOS. Also download Azul Platform Prime.
🌐
GitHub
gist.github.com › filipelenfers › ef3f593deb0751944bb54b744bcac074
Install JDK from tar.gz Ubuntu · GitHub
download open jdk from https://www.openlogic.com/openjdk-downloads?field_java_parent_version_target_id=416&field_operating_system_target_id=426&field_architecture_target_id=391&field_java_package_target_id=396 ... cd /opt/ && \ tar xzf openlogic-openjdk-8u392-b08-linux-x64.tar.gz && \ cd /opt/openlogic-openjdk-8u392-b08-linux-x64/ && \ update-alternatives --install /usr/bin/java java /opt/openlogic-openjdk-8u392-b08-linux-x64/bin/java 2 && \ update-alternatives --install /usr/bin/jar jar /opt/openlogic-openjdk-8u392-b08-linux-x64/bin/jar 2 && \ update-alternatives --install /usr/bin/javac java
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › How-do-I-install-Java-on-Ubuntu
How to install Java 21 on Ubuntu
using /usr/lib/jvm/java-11-openjdk-amd64/bin/jconsole Setting up default-jdk (2:1.21) ... To validate the successful install of Java on Ubuntu, and to ensure the JDK’s bin directory is accessible through the OS’s PATH variable, issue the following command:
🌐
Ask Ubuntu
askubuntu.com › questions › 1204202 › how-to-install-the-jdk-on-ubuntu-linux
How to install the JDK on Ubuntu Linux - Ask Ubuntu
January 19, 2020 - I am trying to install the Java Development Kit (JDK) on Ubuntu Linux distribution, but I am unable to install it. What are the steps to install it on Ubuntu?
🌐
Cherry Servers
cherryservers.com › home › blog › linux › how to install java on ubuntu 22.04 | step-by-step tutorial chatbots
How to Install Java on Ubuntu 22.04 | Step-by-Step Tutorial chatbots | Cherry Servers
November 7, 2025 - There are two main options for installing Java. You can install OpenJDK which is the open-source implementation of Java. This is available on the default Ubuntu repository. Optionally, you can install Oracle JDK which is fully maintained by Oracle.
🌐
Linode
linode.com › docs › guides › how-to-install-openjdk-ubuntu-22-04
Installing OpenJDK on Ubuntu 22.04 | Linode Docs
March 20, 2023 - This guide explains how to install and test the Open Java Development Kit (OpenJDK) version of the Java Runtime Environment (JRE) on Ubuntu 22.04.
🌐
Oracle
docs.oracle.com › en › learn › ol-java-install › index.html
Install Oracle Java SE on Oracle Linux
August 15, 2024 - When using Oracle Linux in Oracle Cloud Infrastructure (OCI), the Oracle Java packages exist in the ol<version>_oci_included repositories. OCI installs and enables these repositories by default when provisioning an Oracle Linux instance. Note: Oracle splits the JDK installation on Oracle Linux into two packages: jdk-<version>-headless and jdk-<version>-headful.
🌐
TecMint
tecmint.com › home › linux distros › ubuntu › how to install java on ubuntu 24.04, ubuntu 22.04, and ubuntu 20.04
How to Install Java (OpenJDK) on Ubuntu 24.04
June 4, 2024 - This tutorial will show you how to install Java on Ubuntu 24.04, Ubuntu 22.04, and Ubuntu 20.04 from the Ubuntu repository and the official Oracle package.