Update-Java-Alternatives: Only Java, but Not Javac Is Changed

I have Java 8 and Java 11 installed in parallel on my Ubuntu 16.04 machine:

$ update-java-alternatives --list
java-1.11.0-openjdk-amd64      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

Having selected Java 11 previously, I now wanted to switch to Java 8 using the command

$ sudo update-java-alternatives --set java-1.8.0-openjdk-amd64

Yet, only the symlink of /usr/bin/java, but not /usr/bin/javac is updated:

$ javac -version
javac 11.0.5

$ java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~16.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

Why is this and how can it be fixed?

3

1 Answer

Java alternatives are configured in .jinfo files, e.g. those in /usr/lib/jvm/.java-1.8.0-openjdk-amd64.jinfo and /usr/lib/jvm/.java-1.11.0-openjdk-amd64.jinfo in your case. When you look at the Java 8 file, you'll see the following line which configures the path for javac, among others for all other Java binaries:

jdkhl javac /usr/lib/jvm/java-8-openjdk-amd64/bin/javac

Unfortunately, it seems like the update-java-alternatives script is outdated on your system, leading to lines prefixed with jdkhl (short for JDK Headless) being ignored. This has also been discussed in Debian bug #825987.

To fix it, just edit /usr/sbin/update-java-alternatives according to this diff.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest