1

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
  • sudo update-alternatives --config java does not work? Nov 8, 2019 at 5:04
  • For just java or javac itself update-alternatives works fine, but the (Open)JDK consists of many more Java tools in both the JRE and the JDK. After all, the purpose of update-java-alternatives is to (conceptually) run update-alternatives for all Java tools defined in the respective .jinfo file.
    – sigalor
    Nov 8, 2019 at 15:24

1 Answer 1

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .