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?

Greenonline
  • 1,759
  • 7
  • 16
  • 21
Fabiola
  • 21
  • 1
  • 3

2 Answers2

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)
GAD3R
  • 63,407
  • 31
  • 131
  • 192
  • Also see [this](https://stackoverflow.com/questions/62084574/openjdk-and-update-alternatives-command) answer for changing between `java` versions. – clownbaby Feb 17 '21 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.

X.LINK
  • 1,288
  • 9
  • 18
  • Can I ask you why installing from the sources or somewhere else is not recommended? – Fabiola Feb 17 '21 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: https://wiki.debian.org/DontBreakDebian – X.LINK Feb 17 '21 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." – kennysong Aug 30 '22 at 05:07