[17-08-2022] thank to @nobody (see comment to the question)

For all older version use this link:

https://launchpad.net/~openjdk-r/+archive/ubuntu/ppa

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt update

and select your version:

sudo apt install openjdk-15-jdk

Answer from B.Kocis on askubuntu.com
Top answer
1 of 3
5

[17-08-2022] thank to @nobody (see comment to the question)

For all older version use this link:

https://launchpad.net/~openjdk-r/+archive/ubuntu/ppa

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt update

and select your version:

sudo apt install openjdk-15-jdk

2 of 3
4

It gives no openjdk-15-jdk in the repos from ubuntu :)

sudo apt list | grep openjdk
[sudo] Passwort für k3ops: 

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

openjdk-11-dbg/focal-updates,focal-security 11.0.9.1+1-0ubuntu1~20.04 amd64
openjdk-11-dbg/focal-updates,focal-security 11.0.9.1+1-0ubuntu1~20.04 i386
openjdk-11-demo/focal-updates 11.0.9.1+1-0ubuntu1~20.04 amd64
openjdk-11-demo/focal-updates,focal-security 11.0.9.1+1-0ubuntu1~20.04 i386
openjdk-11-doc/focal-updates,focal-updates,focal-security,focal-security 11.0.9.1+1-0ubuntu1~20.04 all
openjdk-11-jdk-headless/focal-updates,focal-security 11.0.9.1+1-0ubuntu1~20.04 amd64
openjdk-11-jdk-headless/focal-updates,focal-security 11.0.9.1+1-0ubuntu1~20.04 i386
openjdk-11-jdk/focal-updates,focal-security 11.0.9.1+1-0ubuntu1~20.04 amd64
openjdk-11-jdk/focal-updates,focal-security 11.0.9.1+1-0ubuntu1~20.04 i386
openjdk-11-jre-dcevm/focal 11.0.3+1-1 amd64
openjdk-11-jre-headless/focal-updates,focal-security 11.0.9.1+1-0ubuntu1~20.04 amd64
openjdk-11-jre-headless/focal-updates,focal-security 11.0.9.1+1-0ubuntu1~20.04 i386
openjdk-11-jre-zero/focal-updates 11.0.9.1+1-0ubuntu1~20.04 amd64
openjdk-11-jre-zero/focal-updates,focal-security 11.0.9.1+1-0ubuntu1~20.04 i386
openjdk-11-jre/focal-updates,focal-security 11.0.9.1+1-0ubuntu1~20.04 amd64
openjdk-11-jre/focal-updates,focal-security 11.0.9.1+1-0ubuntu1~20.04 i386
openjdk-11-source/focal-updates,focal-updates,focal-security,focal-security 11.0.9.1+1-0ubuntu1~20.04 all
openjdk-13-dbg/focal-updates 13.0.4+8-1~20.04 amd64
openjdk-13-dbg/focal-updates 13.0.4+8-1~20.04 i386
openjdk-13-demo/focal-updates 13.0.4+8-1~20.04 amd64
openjdk-13-demo/focal-updates 13.0.4+8-1~20.04 i386
openjdk-13-doc/focal-updates,focal-updates 13.0.4+8-1~20.04 all
openjdk-13-jdk-headless/focal-updates 13.0.4+8-1~20.04 amd64
openjdk-13-jdk-headless/focal-updates 13.0.4+8-1~20.04 i386
openjdk-13-jdk/focal-updates 13.0.4+8-1~20.04 amd64
openjdk-13-jdk/focal-updates 13.0.4+8-1~20.04 i386
openjdk-13-jre-headless/focal-updates 13.0.4+8-1~20.04 amd64
openjdk-13-jre-headless/focal-updates 13.0.4+8-1~20.04 i386
openjdk-13-jre-zero/focal-updates 13.0.4+8-1~20.04 amd64
openjdk-13-jre-zero/focal-updates 13.0.4+8-1~20.04 i386
openjdk-13-jre/focal-updates 13.0.4+8-1~20.04 amd64
openjdk-13-jre/focal-updates 13.0.4+8-1~20.04 i386
openjdk-13-source/focal-updates,focal-updates 13.0.4+8-1~20.04 all
openjdk-14-dbg/focal-updates 14.0.2+12-1~20.04 amd64
openjdk-14-dbg/focal-updates 14.0.2+12-1~20.04 i386
openjdk-14-demo/focal-updates 14.0.2+12-1~20.04 amd64
openjdk-14-demo/focal-updates 14.0.2+12-1~20.04 i386
openjdk-14-doc/focal-updates,focal-updates 14.0.2+12-1~20.04 all
openjdk-14-jdk-headless/focal-updates 14.0.2+12-1~20.04 amd64
openjdk-14-jdk-headless/focal-updates 14.0.2+12-1~20.04 i386
openjdk-14-jdk/focal-updates 14.0.2+12-1~20.04 amd64
openjdk-14-jdk/focal-updates 14.0.2+12-1~20.04 i386
openjdk-14-jre-headless/focal-updates 14.0.2+12-1~20.04 amd64
openjdk-14-jre-headless/focal-updates 14.0.2+12-1~20.04 i386
openjdk-14-jre-zero/focal-updates 14.0.2+12-1~20.04 amd64
openjdk-14-jre-zero/focal-updates 14.0.2+12-1~20.04 i386
openjdk-14-jre/focal-updates 14.0.2+12-1~20.04 amd64
openjdk-14-jre/focal-updates 14.0.2+12-1~20.04 i386
openjdk-14-source/focal-updates,focal-updates 14.0.2+12-1~20.04 all
openjdk-8-dbg/focal-updates 8u275-b01-0ubuntu1~20.04 amd64
openjdk-8-dbg/focal-updates,focal-security 8u275-b01-0ubuntu1~20.04 i386
openjdk-8-demo/focal-updates 8u275-b01-0ubuntu1~20.04 amd64
openjdk-8-demo/focal-updates,focal-security 8u275-b01-0ubuntu1~20.04 i386
openjdk-8-doc/focal-updates,focal-updates,focal-security 8u275-b01-0ubuntu1~20.04 all
openjdk-8-jdk-headless/focal-updates 8u275-b01-0ubuntu1~20.04 amd64
openjdk-8-jdk-headless/focal-updates,focal-security 8u275-b01-0ubuntu1~20.04 i386
openjdk-8-jdk/focal-updates 8u275-b01-0ubuntu1~20.04 amd64
openjdk-8-jdk/focal-updates,focal-security 8u275-b01-0ubuntu1~20.04 i386
openjdk-8-jre-headless/focal-updates 8u275-b01-0ubuntu1~20.04 amd64
openjdk-8-jre-headless/focal-updates,focal-security 8u275-b01-0ubuntu1~20.04 i386
openjdk-8-jre-zero/focal-updates 8u275-b01-0ubuntu1~20.04 amd64
openjdk-8-jre-zero/focal-updates,focal-security 8u275-b01-0ubuntu1~20.04 i386
openjdk-8-jre/focal-updates 8u275-b01-0ubuntu1~20.04 amd64
openjdk-8-jre/focal-updates,focal-security 8u275-b01-0ubuntu1~20.04 i386
openjdk-8-source/focal-updates,focal-updates,focal-security 8u275-b01-0ubuntu1~20.04 all
uwsgi-plugin-jvm-openjdk-11/focal 2.0.18-11ubuntu1 amd64
uwsgi-plugin-jwsgi-openjdk-11/focal 2.0.18-11ubuntu1 amd64
uwsgi-plugin-ring-openjdk-11/focal 2.0.18-11ubuntu1 amd64
uwsgi-plugin-servlet-openjdk-11/focal 2.0.18-11ubuntu1 amd64

Ups better you use "apt search openjdk" for the correct command, the first is bad code :P

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.

Discussions

java - Installing jdk8 on ubuntu- "unable to locate package" update doesn't fix - Stack Overflow
I've been trying to install the jdk on my ubuntu after downloading it. first I've used: sudo apt-get update then: sudo apt-get install jdk* (because I didn't want to write the whole long name).... More on stackoverflow.com
🌐 stackoverflow.com
October 20, 2019
Java on Ubuntu 15.10
Hi All, Just a quick note if you’re having trouble installing the openjdk-8-jre-headless package on Ubuntu. I found that I kept getting an “Unable to locate package openjdk-8-jre-headless” error when using apt-get install. Turns out that the openjdk-8 package is in the Universe repository ... More on forum.sierrawireless.com
🌐 forum.sierrawireless.com
0
0
March 10, 2016
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
Cannot install openjdk-8-jre and openjdk-8-jdk
Describe the bug Try to install openjdk-8-jre & openjdk-8-jdk both from pengwin-setup and apt command get the same error: $ apt-get install openjdk-8-jre openjdk-8-jdk -y Reading package lists... D... More on github.com
🌐 github.com
5
April 30, 2019
🌐
USAL
diarium.usal.es › pmgallardo › 2020 › 10 › 12 › how-to-install-jre-or-jdk-in-ubuntu
How to install JRE or JDK in Ubuntu – RunModule
December 12, 2020 - # 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 · “Ubuntu: OpenJDK 8 – Unable to locate package“; stackoverflow · “Installing openjdk-15 returns with unable to locate package error“; stackoverflow
Top answer
1 of 9
53

Command Line option - Ubuntu

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

Then in terminal

sudo apt-get install oracle-java8-installer

When there are multiple Java installations on your System, the Java version to use as default can be chosen. To do this, execute the following command.

sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config javaws

Edit - Manual Java Installation

Download oracle jdk

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Extract zip into desired folder

 e.g  /usr/local/  after extract /usr/local/jdk1.8.0_65

Setup

sudo update-alternatives --install  /usr/bin/java java /usr/local/jdk1.8.0_65/bin/java 1
sudo update-alternatives --install  /usr/bin/javac javac /usr/local/jdk1.8.0_65/bin/javac 1
sudo update-alternatives --install  /usr/bin/javaws javaws /usr/local/jdk1.8.0_65/bin/javaws 1

sudo update-alternatives --set  java /usr/local/jdk1.8.0_65/bin/java
sudo update-alternatives --set  javac /usr/local/jdk1.8.0_65/bin/javac
sudo update-alternatives --set  javaws /usr/local/jdk1.8.0_65/bin/javaws

Edit /etc/environment set JAVA_HOME path for external applications like Eclipse and Idea

2 of 9
11

For me non of the above worked and I had to do as below, and it worked,

sudo -E add-apt-repository ppa:openjdk-r/ppa

and then,

sudo apt-get update

sudo apt-get install openjdk-8-jdk

Reference: https://askubuntu.com/questions/644188/updating-jdk-7-to-8-unable-to-locate-package

🌐
Ubuntu
packages.ubuntu.com › search
Ubuntu – Package Search Results -- openjdk
August 3, 2023 - plucky (25.04) (java): OpenJDK Development Kit (JDK) [universe] 17.0.17+10-1~25.04 [security]: amd64 i386 17.0.15~5ea-1 [ports]: arm64 armhf ppc64el riscv64 s390x
Find elsewhere
🌐
Techoral
techoral.com › blog › java › install-openjdk-15-ubuntu.html
Open Jdk - How To Install OpenJDK Java 15 On Ubuntu 18.04 / ubuntu 20
March 22, 2025 - Note: Here is the list of OpenJDK known-issues related to OpenJDK 15 jdk installation on ubuntu ... Ubuntu package openjdk-8-jdk Ubuntu package openjdk-9-jdk Ubuntu package openjdk-11-jdk Ubuntu package openjdk-13-jdk Ubuntu package openjdk-14-jdk Ubuntu package openjdk-15-jdk If you are looking out for earlier OpenJDK versions, go to OpenJDK Archive
🌐
Sierra Wireless Forum
forum.sierrawireless.com › iot modules › development tools
Java on Ubuntu 15.10 - Development tools - Sierra Wireless Forum
March 10, 2016 - I found that I kept getting an “Unable to locate package openjdk-8-jre-headless” error when using apt-get install. Turns out that the openjdk-8 package is in the Universe repository - which wasn’t enabled by default in the package manager ...
🌐
SpigotMC
spigotmc.org › threads › updating-java-on-older-ubuntu-installations.475777
Updating java on older ubuntu installations | SpigotMC - High Performance Minecraft Software
I updated to openjdk version "11.0.9.1" 2020-11-04 All I did was download openjdk-15.0.1_linux-aarch64_bin.tar.gz and then unzip it with tar xvf...
🌐
Tutorials24x7
java.tutorials24x7.com › blog › how-to-install-openjdk-15-on-ubuntu-20-04-lts
How To Install OpenJDK 15 On Ubuntu 20.04 LTS | Tutorials24x7
October 19, 2020 - # Check version java -version # Configure Java Alternatives sudo update-alternatives --install "/usr/bin/java" "java" "/usr/java/openjdk/jdk-15/bin/java" 1 # Configure Javac Alternatives sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/openjdk/jdk-15/bin/javac" 1 # Check version java -version # Use only in case of multiple JDKs installed # Configure Java sudo update-alternatives --config java # Configure Java Compiler sudo update-alternatives --config javac · The output of these commands is shown in Fig. 3. We might need to configure active Java if it is previously installed on the system. ... These are the basic steps required to install the most recent version of OpenJDK on Ubuntu 20.04 LTS.
🌐
GitHub
github.com › WhitewaterFoundry › Pengwin › issues › 448
Cannot install openjdk-8-jre and openjdk-8-jdk · Issue #448 · WhitewaterFoundry/Pengwin
April 30, 2019 - Describe the bug Try to install openjdk-8-jre & openjdk-8-jdk both from pengwin-setup and apt command get the same error: $ apt-get install openjdk-8-jre openjdk-8-jdk -y Reading package lists... D...
Author   WhitewaterFoundry
🌐
Reddit
reddit.com › r/learnjava › help with installing openjdk and javafx on ubuntu 20.04
Help with installing OpenJDK and JavaFX on Ubuntu 20.04 : r/learnjava
January 22, 2021 - To install openjdk. Sudo apt install openjdk-15-jdk ... I'm not sure how it works, correct me if I'm wrong; I think OpenJDK 15 hasn't been packaged yet or whatever to be installed through the terminal.
🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › software & applications
openjdk-22<SOLVED> - Linux Mint Forums
November 17, 2024 - cant find openjdk-22 in the software manager. i would guess this is due to the fact that its not a lts release (and also a no longer maintained release). the current lts release is openjdk-21 and that can be installed via software manager. so if its all the same to you, just use that. also ...
🌐
w3tutorials
w3tutorials.net › blog › ubuntu-openjdk-8-unable-to-locate-package
Ubuntu OpenJDK 8: Fix 'Unable to Locate Package' Error (Beginner Guide + Oracle JDK vs OpenJDK Comparison) — w3tutorials.net
If you see output like deb http://archive.ubuntu.com/ubuntu/ jammy universe, Universe is enabled. If not, enable it with: sudo add-apt-repository universe sudo apt update # Refresh package lists again · Now, search for OpenJDK 8 in the updated repositories: ... If you see openjdk-8-jdk - OpenJDK Development Kit (JDK) in the results, skip to Step 5.
🌐
GitHub
github.com › replicate › cog › issues › 615
Trying to install Java 8 - Unable to locate package openjdk-8-jdk · Issue #615 · replicate/cog
May 14, 2022 - [stage-0 4/13] RUN --mount=type=cache,target=/var/cache/apt apt-get update -qq && apt-get install -qqy zip unzip openjdk-8-jdk && rm -rf /var/lib/apt/lists/*: #10 3.517 E: Unable to locate package openjdk-8-jdk
Author   replicate