Change JavaJDK in Debian 11 without pain

Oct 13, 2021

My recomendation is to install all JDK version over the packetmanager apt. To change a Java version means not only to change the java binary, it also means to change the other buildtools like javac, javap,keytool,jarsigner, etc.

sudo apt install openjdk-11-jdk openjdk-17-jdk java-common

List all installed JDK`s:

sudo update-java-alternatives -l 

adoptopenjdk-8-hotspot-amd64   1081       /usr/lib/jvm/adoptopenjdk-8-hotspot-amd64
java-1.11.0-openjdk-amd64      1111       /usr/lib/jvm/java-1.11.0-openjdk-amd64
java-1.17.0-openjdk-amd64      1711       /usr/lib/jvm/java-1.17.0-openjdk-amd64

To change all the PATH of the hole JDK simply type:

sudo update-java-alternatives -s java-1.11.0-openjdk-amd64
Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.