Running

Copysudo apt update

before trying to install a second JDK (g00se suggested I had to) helped. It was ChatGPT's advice. If you need to know where the JDK is installed, try (also GPT's idea)

Copyupdate-alternatives --list java

With that information, you should be able to register that JAVA_HOME thing. In my case, it was

Copyexport JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64

I hope it helps somebody one day

Answer from Sergey Zolotarev on Stack Overflow
🌐
LinuxCapable
linuxcapable.com › home › ubuntu › how to install openjdk 17 on ubuntu 26.04, 24.04 and 22.04
How to Install OpenJDK 17 on Ubuntu 26.04, 24.04 and 22.04 - LinuxCapable
April 29, 2026 - If APT reports E: Unable to locate package openjdk-17-jdk or has no installation candidate, your package index is outdated or the universe repository component is disabled.
🌐
GitHub
github.com › termux › termux-packages › issues › 9733
[Bug]: openjdk-17: can't install the package · Issue #9733 · termux/termux-packages
April 1, 2022 - Problem description After apt update && apt full-upgrade -y, when I try to install openjdk-17 by apt install openjdk-17 -y, it says the package is not available. See: What steps will reproduce the bug? apt update && apt full-upgrade -y a...
Author   termux
🌐
LinuxShout
linux.how2shout.com › home › installing openjdk 17 ubuntu such as on 24.04 or 22.04 linux
Installing OpenJDK 17 Ubuntu such as on 24.04 or 22.04 Linux - LinuxShout
October 15, 2024 - Package Not Found: If you see an error like E: Unable to locate package openjdk-17-jdk, make sure your Ubuntu version supports OpenJDK 17 and run sudo apt update.
🌐
Reddit
reddit.com › r/linux4noobs › cant install java on debian
r/linux4noobs on Reddit: Cant install java on debian
October 14, 2024 -

If i try to install using sudo apt-get install openjdk i get unable to locate package openjdk and if i try to add a repo i get the error in the photo so i cant install java using this repo i found in a tutorial

🌐
Reddit
reddit.com › r/linux4noobs › error while installing oraclejdk 17 on ubuntu 22.04
r/linux4noobs on Reddit: Error while installing OracleJDK 17 on Ubuntu 22.04
January 28, 2023 - Ill recommend you use OpenJDK instead of Oracle, but anyways you can use " apt search jdk " and it should spit every package it finds that you can install afterwards with apt install
🌐
Mm-notes
mm-notes.com › ubuntu › java › 2021 › 11 › 25 › installing-jdk-ubuntu.html
Installing JDK on Ubuntu | Mahendran’s Notes
November 25, 2021 - parallels@ubuntu-linux-20-04-desktop:~$ sudo apt install openjdk-17-jdk · if you get “Unable to locate package” error like this try sudo apt update … · $ sudo apt install openjdk-17-jdk [sudo] password for subanitha: Reading package lists... Done Building dependency tree Reading state ...
🌐
keep_growing
keepgrowing.in › home › how to install openjdk 17 on ubuntu
How to install OpenJDK 17 on Ubuntu - keep_growing
January 11, 2022 - The output should include the openjdk-17-jdk package as seen in the screenshot below: To make sure that the package list is up to date, remember to run the aforementioned apt update command first. We’ve just verified that the package is available, so we can finally install it with the following command: We can verify the location of the newly installed java files with the update-alternatives command:
Find elsewhere
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.

🌐
GitHub
github.com › karma9874 › AndroRAT › issues › 203
E: Unable to locate package openjdk-17 · Issue #203 · karma9874/AndroRAT
July 20, 2022 - E: Unable to locate package openjdk-17#203 · Copy link · Labels · stale · CrazyCraziness · opened · on Jul 20, 2022 · Issue body actions · I can't install help · No one assigned · stale · No projects · No milestone · None yet · No branches or pull requests ·
Author   karma9874
🌐
Reddit
reddit.com › r/linux4noobs › messed up and now can't get jdk17 back. package 'java-common' has no installation candidate
r/linux4noobs on Reddit: Messed up and now can't get JDK17 back. Package 'java-common' has no installation candidate
August 23, 2024 -

I run Debian 12 and thought of installing jdk21, then by misstake wrote jdk17 and in the process messed something up when deleting jdk17. so no I have no JDK and when trying to install jdk17 I first get:

sudo apt-get install openjdk-17-jdk
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:


The following packages have unmet dependencies:
 openjdk-17-jre-headless : Depends: java-common (>= 0.28) but it is not installable
E: Unable to correct problems, you have held broken packages.

I then try sudo apt-get install openjdk-17-jre-headless and get:

The following packages have unmet dependencies:
 openjdk-17-jre-headless : Depends: java-common (>= 0.28) but it is not installable
E: Unable to correct problems, you have held broken packages.

I then try this: sudo apt-get install java-common and get:

E: Package 'java-common' has no installation candidate

My sources.d file look like this:

deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware


deb http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
deb-src http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware


deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware

What should I do to resolve this?

🌐
GitHub
github.com › PrismLauncher › prismlauncher.org › issues › 886
`openjdk-17-jdk` no longer exists on Debian 13 (Trixie) · Issue #886 · PrismLauncher/prismlauncher.org
October 30, 2025 - Snippet from https://prismlauncher.org/wiki/development/build-instructions/linux/#build-dependencies: Build dependencies Java JDK (openjdk-17-jdk on Debian-based system) Terminal: $ apt info openjdk-17-jdk Notice: Unable to locate packag...
Author   PrismLauncher
🌐
DietPi
dietpi.com › troubleshooting
Problems installing Open JDK 17 - Troubleshooting - DietPi Community Forum
October 24, 2025 - Hello, I’m having trouble installing the “openjdk-17-jdk-headless” package via apt on the current DietPi. What would be the easiest way to install Java 17? I would like to install and test the “Thingsboard” software, but it requires Java 17. I tried openjdk-21 and it does not work.
🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › software & applications
openjdk-22<SOLVED> - Linux Mint Forums
November 17, 2024 - mega_mind@mega-mind-HP-Laptop-15-da1xxx:~$ java --version Command 'java' not found, but can be installed with: sudo apt install openjdk-17-jre-headless # version 17.0.12+7-1ubuntu2~24.04, or sudo apt install openjdk-21-jre-headless # version 21.0.4+7-1ubuntu2~24.04 sudo apt install default-jre # version 2:1.17-75 sudo apt install openjdk-11-jre-headless # version 11.0.24+8-1ubuntu3~24.04.1 sudo apt install openjdk-8-jre-headless # version 8u422-b05-1~24.04 sudo apt install openjdk-19-jre-headless # version 19.0.2+7-4 sudo apt install openjdk-20-jre-headless # version 20.0.2+9-1 sudo apt instal
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

🌐
openHAB Community
community.openhab.org › setup, configuration and use › migration
Unable to install Java 17 - Migration - openHAB Community
July 27, 2023 - Hi all, I am unable to install OpenJDK 17 on my Pi which is required for running Openhab 4. The setup fails with the following error message: The following packages have unmet dependencies: openjdk-17-jdk : Depends: openjdk-17-jre (= 17.0.8+7-1) but it is not going to be installed Depends: openjdk-17-jdk-headless (= 17.0.8+7-1) but it is not going to be installed Depends: libc6 (>= 2.34) but 2.31-13+rpi1+deb11u6 is to be installed Recommends: libxt-dev but it is not going to be installed ...
🌐
GitHub
github.com › xiv3r › Burpsuite-Professional › issues › 68
minor errors in install.sh · Issue #68 · xiv3r/Burpsuite-Professional
August 26, 2025 - Hello, just for your knowledge, when i run install.sh on kali linux (latest version to date - 2025.2) i get this Package openjdk-17-jre is not available, but is referred to by another package. This may mean that the package is missing, h...
Author   xiv3r