To install OpenJDK 11 in Ubuntu, use the commands listed below.

  1. Add the repository
sudo add-apt-repository ppa:openjdk-r/ppa
  1. Update package list
sudo apt-get update
  1. Install openjdk-11-jdk
sudo apt install openjdk-11-jdk
Answer from Tejas Lotlikar on askubuntu.com
Discussions

Problem installing openjdk-11-jdk
What Debian version? Bookworm ships openjdk-17-jdk. 11 was in buster. As to why you're running a v16 JRE, no idea, you likely have some JRE in the path or installed some weird package from outside the Debian repositories. Running which java should at least give you a hint. More on reddit.com
🌐 r/debian
6
1
September 6, 2023
Unable to locate package openjdk-11-jre-headless 7.17 ubuntu-2004-aarch64
Exit-code 17 when calling ... docker.io/library/ubuntu:18.04@sha256:152dc042452c496007f07ca9127571cb9c29697f42acbfad72324b2bb2e43c98 #4 DONE 0.0s #5 [geoip-fixture 2/3] RUN apt-get update -qqy #5 CACHED #6 [geoip-fixture 3/3] RUN apt-get install -qqy openjdk-11-jre-headless #6 3.269 E: Unable to locate package ... More on github.com
🌐 github.com
3
April 18, 2024
Why is Debian unable to locate package openjdk-16-jre-headless? - Unix & Linux Stack Exchange
I am using Debian 10.6. $ sudo apt install openjdk-16-jre-headless Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package openjd... More on unix.stackexchange.com
🌐 unix.stackexchange.com
December 30, 2021
java - Ubuntu: OpenJDK 8 - Unable to locate package - Stack Overflow
So I just installed Ubuntu, and this is my first time working in a Linux environment, so bear with my noobishness here. Anyway, I downloaded the Java 8 JDK directly from Oracle, but I understand t... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Stack Overflow
stackoverflow.com › questions › 57960603 › e-unable-to-locate-package-openjdk-11-jdk
maven - E: Unable to locate package openjdk-11-jdk - Stack Overflow
FROM maven:3-jdk-11 # Common files and utils for build RUN apt-get update && apt-get install -y make fakeroot rpm dpkg-dev apt-utils wget unzip RUN apt-get install -y -q software-properties-common desktop-file-utils # Then Wine with all deps RUN dpkg --add-architecture i386 && apt-get update RUN apt-get install -y --install-recommends wine RUN apt-cache search openjdk RUN apt-get install -y openjdk-11-jdk RUN apt install -y openjfx11 libopenjfx-java libopenjfx-jni RUN apt-get install -y --install-recommends wine32 ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64 ENV JAVAFX_HOME /usr/share/java/openjfx11 # And we ready to play with our code ARG SRCDIR=. ARG DSTDIR=/usr/src/CryptoStock ARG CACHEDIR=./cache # Subject to be used here but should be command line, sic!
🌐
RoseIndia
roseindia.net › answers › viewqa › Java-Beginners › 33038-Unable-to-locate-package-openjdk-11-jdk.html
Unable to locate package openjdk-11-jdk
July 29, 2018 - Open JDK is still not available in PPA so, you are not able to install. It will release in September and it can be installed with the command: ... Unable to locate package openjdk-11-jdk Unable to locate package openjdk-11-jdk Hi, I want to install open... openjdk-11-jdk Reading package lists...
🌐
GitHub
github.com › elastic › elasticsearch › issues › 107613
Unable to locate package openjdk-11-jre-headless 7.17 ubuntu-2004-aarch64 · Issue #107613 · elastic/elasticsearch
April 18, 2024 - Exit-code 17 when calling ... docker.io/library/ubuntu:18.04@sha256:152dc042452c496007f07ca9127571cb9c29697f42acbfad72324b2bb2e43c98 #4 DONE 0.0s #5 [geoip-fixture 2/3] RUN apt-get update -qqy #5 CACHED #6 [geoip-fixture 3/3] RUN apt-get install -qqy openjdk-11-jre-headless #6 3.269 E: Unable to locate package ...
Author   elastic
🌐
Ubuntu
packages.ubuntu.com › bionic › openjdk-11-jdk
Ubuntu – Error
two or more packages specified (openjdk-11-jdk bionic) Content Copyright © 2026 Canonical Ltd.; See license terms. Ubuntu is a trademark of Canonical Ltd. Learn more about this site.
Find elsewhere
🌐
Java Tech Blog
javanexus.com › blog › openjdk-11-installation-errors-ubuntu-18-04
Fixing Common OpenJDK 11 Installation Errors on Ubuntu 18.04 | Java Tech Blog
February 6, 2024 - First, ensure your package repository is updated (sudo apt update). If the issue persists, consider adding a third-party PPA (Personal Package Archive) that hosts OpenJDK 11: ... Some applications require the JAVA_HOME environment variable to be set to your JDK's installation path.
🌐
AccuWeb Hosting
manage.accuwebhosting.com › knowledgebase › 3375 › How-to-Install-OpenJDK-JAVA-11or8-on-Ubuntu.html
How to Install OpenJDK JAVA 11/8 on Ubuntu? - AccuWebHosting
It includes both the Java Runtime Environment (JRE) and the Java Development Kit (JDK), required to run and develop Java applications. This article explains how to install OpenJDK Java 11 or 8 on an Ubuntu-based system. You can follow the steps in this article to install JAVA OpenJDK in all Ubuntu versions. Run the following command to list all available OpenJDK packages for Ubuntu OS:
Top answer
1 of 15
149

UPDATE: installation without root privileges below


I advise you to not install packages manually on ubuntu system if there is already a (semi-official) repository able to solve your problem. Further, use Oracle JDK for development, just to avoid (very sporadic) compatibility issues (i've tried many years ago, it's surely better now).

Add the webupd8 repo to your system:

Copysudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

Install your preferred version of jdk (versions from java-6 to java-9 available):

Copysudo apt-get install oracle-java8-installer

You can also install multiple version of jdk, mixing openjdk and oracle versions. Then you can use the command update-java-alternatives to switch between installed version:

Copy# list available jdk
update-java-alternatives --list

# use jdk7
sudo update-java-alternatives --set java-7-oracle

# use jdk8
sudo update-java-alternatives --set java-8-oracle

Requirements

If you get add-apt-repository: command not found be sure to have software-properties-common installed:

Copysudo apt-get install software-properties-common

If you're using an older version Ubuntu:

Copysudo apt-get install python-software-properties

JDK installation without root privileges

If you haven't administrator rights on your target machine your simplest bet is to use sdkman to install the zulu certified openjdk:

Copycurl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install java

NOTE: sdkman allow to install also the official Oracle JDK, although it's not a the default option. View available versions with:

Copysdk ls java

Install the chosen version with:

Copysdk install java <version>

For example:

Copysdk install java 9.0.1-oracle

Glossary of commands

  • sudo <command> [command_arguments]: execute a command with the superuser privilege.

  • add-apt-repository <PPA_id>: Ubuntu (just like every Debian derivatives and generally speaking every Linux distribution) has a main repository of packages that handle things like package dependencies and updating. In Ubuntu is possible to extend the main repository using a PPA (Personal Package Archive) that usually contains packages not available in the system (just like oracle jdk) or updated versions of available ones (example: LibreOffice 5 in LTS is available only through this PPA).

  • apt-get [install|update|upgrade|purge|...]: it's "the" command-line package handler used to manipulate the state of every repository on the system (installing / updating / upgrading can be viewed as an alteration of the repository current state).

In our case: with the command sudo add-apt-repository ppa:webupd8team/java we inform the system that the next repository update must retrieve packages information also from webupd8 repo.

With sudo apt-get update we actually update the system repository (all this operations requires superuser privileges, so we prepend sudo to the commands).

sudo apt-get install oracle-java8-installer

  • update-java-alternatives (a specific java version of update-alternatives): in Ubuntu several packages provides the same functionality (browse the internet, compile mails, edit a text file or provides java/javac executables...). To allows the system to choose the user favourites tool given a specific task a mechanism using symlinks under /etc/alternatives/ is used. Try to update the jdk as indicated above (switch between java 7 and java 8) and view how change the output of this command:

    ls -l /etc/alternatives/java*

In our case: sudo update-java-alternatives --set java-8-oracle update symlinks under /etc/alternatives to point to java-8-oracle executables.

Extras:

  • man <command>: start using man to read a really well written and detailed help on (almost) every shell command and its options (every command i mention in this little answer has a man page, try man update-java-alternatives).

  • apt-cache search <search_key>: query the APT cache to search for a package related with the search_key provided (can be the package name or some word in package description).

  • apt-cache show <package>: provides APT information for a specific package (package version, installed or not, description).

2 of 15
133

As you can see I only have java 1.7 installed (on a Ubuntu 14.04 machine).

Copyupdate-java-alternatives -l
java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64

To install Java 8, I did,

Copysudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jdk

Afterwards, now I have java 7 and 8,

Copyupdate-java-alternatives -l
java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1069 /usr/lib/jvm/java-1.8.0-openjdk-amd64

BONUS ADDED (how to switch between different versions)

  • run the follwing command from the terminal:

sudo update-alternatives --config java

CopyThere are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      auto mode
  1            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
* 2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1069      manual mode

Press enter to keep the current choice[*], or type selection number:

As you can see I'm running open jdk 8. To switch to to jdk 7, press 1 and hit the Enter key. Do the same for javac as well with, sudo update-alternatives --config javac.

Check versions to confirm the change: java -version and javac -version.

🌐
Reddit
reddit.com › r/linux4noobs › unable to install open java
r/linux4noobs on Reddit: Unable to install open Java
February 9, 2019 -

I am following instructions from here https://linuxconfig.org/how-to-install-java-on-ubuntu-18-04-bionic-beaver-linux but I get "E: Unable to locate package openjdk-8-jdk" in terminal.

Also if i type "java" I get

sudo apt install default-jre
sudo apt install openjdk-11-jre-headless sudo apt install openjdk-8-jre-headless

None of these work either. "E: Package 'default-jre' has no installation candidate"

🌐
Ubuntu
packages.ubuntu.com › search
Ubuntu – Package Search Results -- openjdk
August 3, 2023 - plucky (25.04) (doc): OpenJDK Development Kit (JDK) documentation [universe] 11.0.29+7-1ubuntu1~25.04 [security]: all
🌐
DZone
dzone.com › coding › frameworks › installing openjdk 11 on ubuntu 18.04
Installing OpenJDK 11 on Ubuntu 18.04
October 1, 2018 - This is very simple, you just need the following package. ... Nevertheless, be sure to check what Java version that actually installs. $ java -version openjdk version "10.0.2" 2018-07-17 OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.2) OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.2, mixed mode) That's easy, too — you just have to download a tarball and extract it somewhere. % wget https://download.java.net/java/GA/jdk11/28/GPL/openjdk-11+28_linux-x64_bin.tar.gz -O /tmp/openjdk-11+28_linux-x64_bin.tar.gz % sudo tar xfvz /tmp/openjdk-11+28_linux-x64_bin.tar.gz --directory /usr/lib/jvm % rm -f /tmp/openjdk-11+28_linux-x64_bin.tar.gz
🌐
LinuxQuestions.org
linuxquestions.org › questions › linux-newbie-8 › e-unable-to-locate-package-jdk-4175617153
E: Unable to locate package Jdk
can someone help me pleaseto install jdk, i am using ubuntu 16.06LTs gervais@gervais:~ sudo apt install jdk Reading package lists... Done Building