Can't switch to Java 11 (Ubuntu)

ogerardin's Avatar


18 Feb, 2022 01:08 AM

Even though I specified stack: jdk 11 in my Linux (Ubuntu2004) build settings, it seems that Java 9 is still installed and is the default Java version as evidenced by mvn -v:

Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 9.0.4, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-9-openjdk-amd64
Default locale: en, platform encoding: UTF8
OS name: "linux", version: "5.11.0-1021-azure", arch: "amd64", family: "unix"
Link to build:

Running update-java-alternatives -l shows that OpenJDK 11 and 8 are available:

java-1.11.0-openjdk-amd        1111       /usr/lib/jvm/java-1.11.0-openjdk-amd64
java-1.8.0-openjdk-amd64       1081       /usr/lib/jvm/java-1.8.0-openjdk-amd64

However, using sudo update-java-alternatives -s java-1.11.0-openjdk-amd64 fails with a bunch of errors, see

Why does update-java-alternatives not work? How do I switch to JDK 11?

  1. 1 Posted by ogerardin on 18 Feb, 2022 02:23 AM

    ogerardin's Avatar

    Apparently JAVA_HOME is set to /usr/lib/jvm/java-9-openjdk-amd64, so Maven uses it and not the default Java.

    The solution I found is:

    export PATH=/usr/lib/jvm/java-11-openjdk-amd64/bin:$PATH
    unset JAVA_HOME

    I expected stack: jdk 11 to both set the default JDK to Java 11 and set JAVA_HOME to the same, but apparently all it does is set a symbolic link default-java -> java-1.11.0-openjdk-amd64 in /usr/lib/jvm

  2. Support Staff 2 Posted by Feodor Fitsner on 18 Feb, 2022 04:57 AM

    Feodor Fitsner's Avatar

    This is the script used by JDK stack component:

    export JAVA_HOME=${!JVAR}
    export PATH=$JAVA_HOME/bin:{path-without-/usr/lib/jvm/*}

    Will take a look what's wrong with that.

  3. Feodor Fitsner closed this discussion on 20 Apr, 2022 09:01 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac