2

I have Debian 10 and openjdk-11-jdk installed from the Debian repository. I have to run a program that was compiled with Java runtime version 58 so I need to update it.

I downloaded the .tar.gz of OpenJDK 15 available at java.net. I extracted the file in /usr/local/bin since it was listed in my PATH variable. I run update-alternatives --list java but I have only OpenJDK 11 listed.

How can I install correctly OpenJDK 15?

2 Answers 2

4
sudo update-alternatives --config java update-alternatives: error: no alternatives for java 

The installed java versions need to be added to update-alternatives:

adding jdk-11 with 10 priority :

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-11-openjdk-amd64/bin/java 10 

adding jdk-15 with 20 priority (suppose you have extracted the tarball to /usr/lib/jvm/ directory. In your case replace /usr/lib/jvm/jdk-15.0.2/bin/java with /usr/local/bin/jdk-15.0.2/bin/java)

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-15.0.2/bin/java 20 

Check it:

 sudo update-alternatives --list java /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/jdk-15.0.2/bin/java 

and

sudo update-alternatives --config java 

sample output:

There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/jdk-15.0.2/bin/java 20 auto mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 10 manual mode 2 /usr/lib/jvm/jdk-15.0.2/bin/java 20 manual mode Press <enter> to keep the current choice[*], or type selection number: 

Check the java version, in the above example the default version is jdk-15:

java --version openjdk 15.0.2 2021-01-19 OpenJDK Runtime Environment (build 15.0.2+7-27) OpenJDK 64-Bit Server VM (build 15.0.2+7-27, mixed mode, sharing) 
1
  • Also see this answer for changing between java versions. Commented Feb 17, 2021 at 17:07
0

The answer is rather pretty simple but not very recommended, just set apt to prefer buster-updates's packages, append Debian 11's (Bullseye) repositories to your /etc/sources.list, then force it to install/update the openjdk-17-jdk.

This means that you'll have a FrankenDebian, but it'll still be far better than installing from the sources or from somewhere else.

You can also do this far easier by using a GUI: synaptic.

Edit: I also forgot, but GAD3R is also right about the update-alternatives thing, you may also have to do that too if installing from the packages don't trigger it.

3
  • Can I ask you why installing from the sources or somewhere else is not recommended? Commented Feb 17, 2021 at 14:00
  • 1
    Debian packages are (well, obviously) not just simple compiled sources, there's sometimes tons of modifications that you can be unaware of, which some can be pretty sensitive. If not done properly, installing from sources can break your system, even from very known, "simple" or seemingly OS-agnostic packages. The key word here is FrankenDebian: wiki.debian.org/DontBreakDebian Commented Feb 17, 2021 at 20:50
  • That link seems to suggest that making a FrankenDebian is worse than building from source: "If you're trying to install software that isn't available in the current Debian Stable release, it's not a good idea to add repositories for other Debian releases." Commented Aug 30, 2022 at 5:07

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.