Before I start, please note that the JDK also contains the JRE within it.

Method 1:

To install the openJDK JDK and JRE 8 use (replace 8 with the version you want, such as 7 or 6):

sudo apt-get install openjdk-8-jdk

Method 2:

If you instead want to install the official Oracle JDK and JRE and definitely want to install through apt-get then do (you can replace the 8 with other versions such as 9, or 7):

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

Method 3:

Or if you want to install the official Oracle Java version manually:

  1. Go here and click the download button:

  2. Select the Accept License Agreement radio button (once you have read the license agreement).

  3. Select the file you want to download, if you are running on a 32-bit machine click jdk-[javaversion]-linux-i586.tar.gz ([javaversion] replaced with the Java version, such as 8u60), if 64-bit then jdk-[javaversion]-linux-x64.tar.gz.

  4. Launch Terminal (CTRL + ALT + T), then cd to the directory where you downloaded the file to (probably ~/Downloads), and run tar -xvf /path/to/file.tar.gz to unpack that archive into the directory the file is in, you may then move that unpacked archive into a desired location, such as the /opt directory (storing executable files in your home directory is a security risk).

  5. Once you have done the above you may delete the original .tar.gz file, and then open up your ~/.bashrc file in a desired file editor such as gedit or vim, I will be using vim in this example (install it with sudo apt-get install vim if it is not already installed). So run vim ~/.bashrc and then insert two new lines at the bottom of the file which read (that is with /path/to/unpacked/archive replaced with the path to the archive you just unpacked):

    JAVA_HOME=/path/to/unpacked/archive
    export PATH=$PATH:$JAVA_HOME/bin
    
  6. Either restart Terminal or run source ~/.bashrc to start using the new .bashrc file.

    Note: With this method you will have to carry on doing this every time there is a new Java version released which it will not notify you about.

Answer from user364819 on askubuntu.com
🌐
Ubuntu
ubuntu.com › tutorials › install-jre
Install the Java Runtime Environment | Ubuntu
The Java Runtime Environment (JRE) is required to run Java programs. Nowadays there are many JRE packages available from a variety of projects and companies, but the two most popular on Ubuntu are OpenJDK and Oracle HotSpot.
🌐
Ubuntu
documentation.ubuntu.com › ubuntu-for-developers › reference › availability › java
Available Java versions - Ubuntu for Developers
3 days ago - This page lists Java versions available in Ubuntu releases, including CRaC and GraalVM. Ubuntu OpenJDK (deb) packages:,,, Ubuntu version, available Java versions, java-common version,,, 26.10 (Ston...
🌐
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 - Learn how to install Java (JRE & JDK) on Ubuntu using apt. Step-by-step guide to setting up Java, verifying installation, and managing multiple versions.
🌐
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
Raspberry PI with Java: programming ... does not come with Java’s JDK preinstalled, it does come prepackaged with the ability to easily install Java with the apt command....
🌐
Oracle
java.com › en › download › help › linux_x64_install.html
Linux 64-bit installation instructions for Java
Follow these steps to download and install Java for Linux. ... This procedure installs the Java Runtime Environment (JRE) for 64-bit Linux, using an archive binary file (.tar.gz).
🌐
OVHcloud
us.ovhcloud.com › home › how to install java on ubuntu 22.04 ?
How to install Java on Ubuntu 22.04 ?
In this tutorial, you will learn how to install a Java Development Kit (JDK) on the Ubuntu 22.04 Linux distribution.
Top answer
1 of 4
8

Before I start, please note that the JDK also contains the JRE within it.

Method 1:

To install the openJDK JDK and JRE 8 use (replace 8 with the version you want, such as 7 or 6):

sudo apt-get install openjdk-8-jdk

Method 2:

If you instead want to install the official Oracle JDK and JRE and definitely want to install through apt-get then do (you can replace the 8 with other versions such as 9, or 7):

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

Method 3:

Or if you want to install the official Oracle Java version manually:

  1. Go here and click the download button:

  2. Select the Accept License Agreement radio button (once you have read the license agreement).

  3. Select the file you want to download, if you are running on a 32-bit machine click jdk-[javaversion]-linux-i586.tar.gz ([javaversion] replaced with the Java version, such as 8u60), if 64-bit then jdk-[javaversion]-linux-x64.tar.gz.

  4. Launch Terminal (CTRL + ALT + T), then cd to the directory where you downloaded the file to (probably ~/Downloads), and run tar -xvf /path/to/file.tar.gz to unpack that archive into the directory the file is in, you may then move that unpacked archive into a desired location, such as the /opt directory (storing executable files in your home directory is a security risk).

  5. Once you have done the above you may delete the original .tar.gz file, and then open up your ~/.bashrc file in a desired file editor such as gedit or vim, I will be using vim in this example (install it with sudo apt-get install vim if it is not already installed). So run vim ~/.bashrc and then insert two new lines at the bottom of the file which read (that is with /path/to/unpacked/archive replaced with the path to the archive you just unpacked):

    JAVA_HOME=/path/to/unpacked/archive
    export PATH=$PATH:$JAVA_HOME/bin
    
  6. Either restart Terminal or run source ~/.bashrc to start using the new .bashrc file.

    Note: With this method you will have to carry on doing this every time there is a new Java version released which it will not notify you about.

2 of 4
1

Open terminal and type

sudo apt-get install openjdk-7-jre

This package contains the Java Runtime Environment

🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to install java on ubuntu
How to Install Java on Ubuntu
February 20, 2025 - Install one or several Java packages on your system, or choose a specific version by specifying the version number. By default, Ubuntu includes OpenJDK as the Java Development Kit (JDK) and Java Runtime Environment (JRE).
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › techtips › how-to-install-java-in-ubuntu
How to install Java in Ubuntu - GeeksforGeeks
February 14, 2026 - Java is now present on the Ubuntu system. This method allows installation of a specific Java version. Command: sudo add-apt-repository ppa:linuxuprising/java -y · Command: sudo apt-get update · Command: sudo apt install oracle-java<versio...
🌐
Ubuntu
ubuntu.com › toolchains › java
Java support - Canonical builds of OpenJDK for Ubuntu | Ubuntu
Innovate with Java and run your preferred build of OpenJDK on Ubuntu. Bring stability to your Java environment with up to 12 years of long-term support for all OpenJDK LTS releases, through Ubuntu Pro and Ubuntu Pro + Support.
🌐
Hostinger
hostinger.com › home › tutorials › how to install java on ubuntu
How to Install Java on Ubuntu
January 13, 2026 - Check this article to learn how to install Java on Ubuntu: 1. Update the package index 2. Install JRE 3. Install a specific Java version and more.
🌐
IONOS
ionos.com › digital guide › server › configuration › install java on ubuntu
How to install Java on Ubuntu step by step - IONOS
October 31, 2022 - It’s well known that you can install Java on Windows 11 but adding it to a machine running Linux is just as easy. To install Java on Ubuntu all you need is the command sudo apt install default-jre.
🌐
LinuxConfig
linuxconfig.org › home › how to install and switch java versions on ubuntu linux
How to Install and Switch Java Versions on Ubuntu Linux
September 21, 2025 - Learn how to install and switch Java versions on Ubuntu, using Ubuntu repo or Oracle package. Essential for managing Java on Ubuntu systems.
🌐
CyberPanel
cyberpanel.net › blog › install-java-on-linux-ubuntu
Install Java on Linux Ubuntu Easily: Your Ultimate Guide
April 7, 2025 - Is it possible to install multiple Java versions on Ubuntu? Yes, and you can select which one to use via sudo update-alternatives –config java. ... You can run readlink -f $(which java) to get the path of your Java binary.
🌐
BlueVPS
bluevps.com › blog › step-by-step guide: how to install java on ubuntu 22.04
Step-by-Step Guide: How to Install Java on Ubuntu 22.04 - Blog - BlueVPS
September 25, 2023 - Choose the suitable version of OpenJDK and install it using the apt repository. ... Now, press ‘y’ and ‘Enter’ to proceed with the installation. The above command will install the complete JDK platform of the OpenJDK 17 version.
🌐
Ubuntu
documentation.ubuntu.com › ubuntu-for-developers › tutorials › java-use
Develop with Java on Ubuntu - Ubuntu for Developers
3 weeks ago - This tutorial provides basic guidance on using the Java toolchain for development on Ubuntu. It shows how to create a ‘Hello, world!’ program and explains how to build projects using Gradle or Mave...
🌐
Ubuntu
documentation.ubuntu.com › ubuntu-for-developers › howto › java-setup
How to set up a development environment for Java on Ubuntu - Ubuntu for Developers
3 weeks ago - This article covers how to install the Java toolchain and development environment on Ubuntu. Java is a popular programming language supported on many platforms. Installing Eclipse IDE: The quickest...
🌐
Linuxize
linuxize.com › home › java › how to install java on ubuntu 24.04
How to Install Java on Ubuntu 24.04 | Linuxize
May 3, 2026 - Install Java 25, Java 21, and Oracle JDK on Ubuntu 24.04. This guide covers OpenJDK packages, default Java selection, and JAVA_HOME setup.