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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like