Set JDK 8 as the default Java on Debian 8

I'm trying to set the Java SDK 8 tools (installed from the debian backports repo) as the defaults.

# update-java-alternatives --list
java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1069 /usr/lib/jvm/java-1.8.0-openjdk-amd64

# update-java-alternatives --set /usr/lib/jvm/java-1.8.0-openjdk-amd64
update-alternatives: error: no alternatives for mozilla-javaplugin.so
update-java-alternatives: plugin alternative does not exist: /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/IcedTeaPlugin.so

Hum, well aside from that error (which I am lead to believe is merely a warning according to https://askubuntu.com/questions/141791/is-there-a-way-to-update-all-java-related-alternatives . If not, I don't know how to fix this, as there is no icedtea plugin for jdk8 that I can see), this should have done the trick, right?

But many Java tools still point to Java 7:

# update-alternatives --get-selections | grep java
appletviewer                   manual   /usr/lib/jvm/java-8-openjdk-amd64/bin/appletviewer
extcheck                       auto     /usr/lib/jvm/java-7-openjdk-amd64/bin/extcheck
idlj                           auto     /usr/lib/jvm/java-7-openjdk-amd64/bin/idlj
jar                            auto     /usr/lib/jvm/java-7-openjdk-amd64/bin/jar
jarsigner                      auto     /usr/lib/jvm/java-7-openjdk-amd64/bin/jarsigner
java                           manual   /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
javac                          auto     /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
javadoc                        auto     /usr/lib/jvm/java-7-openjdk-amd64/bin/javadoc
...

What gives? Broken?

EDIT:

Worked around this with:

for i in `update-alternatives --get-selections | grep java | awk '{print $1}'`; do update-alternatives --config $i; done

This will manually prompt you for each and every tool. Which takes about a minute. Still, I would like to know if there is a better way.


update-java-alternatives has options to update --jre-headless, --jre, and --plugin separately.

Using

sudo update-java-alternatives --jre-headless --jre --set java-1.8.0-openjdk-amd64

worked for me on a Debian Jessie server with no plugin installed.


In ubuntu, JDK1.8 does not stay installed by default. When you list for java alternatives

$ update-java-alternatives -l
java-1.11.0-openjdk-amd64      1101       /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
java-7-oracle                  1082       /usr/lib/jvm/java-7-oracle

java-1.8.0-openjdk-amd64 in this list is not JDK, but JRE instead. JRE doesn't contain all the necessary development tools like javac, javadoc, etc. You can verify if the bin directory contains these files. This is the reason of not registering these tools.

So, first you have to install JDK

sudo apt install openjdk-8-jdk

And then change the alternative

sudo update-java-alternatives -s java-1.8.0-openjdk-amd64