18

I have Java 11 and 8 in my Ubuntu 18.04, side by side. I mean to set Java 8 as the default.

What I get:

    $ sudo 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/lib/IcedTeaPlugin.so

How can I get both plugins if they exist, work.

I am not sure if using (see this)

    sudo update-java-alternative —jre-headless -s java-1.8.0-openjdk-amd64

is ok, so I did not try it. Could it break anything? The Following are results after update-java-alternatives

    $ sudo update-alternatives --config java
    There are 2 choices for the alternative java (providing /usr/bin/java).
  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      manual mode
* 2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode

$ java -version openjdk version "1.8.0_191" OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12) OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

This is the opposite change from

update-alternatives: error: no alternatives for mozilla-javaplugin.so

https://ubuntuforums.org/showthread.php?t=2402155

Related:

https://serverfault.com/questions/814064/set-jdk-8-as-the-default-java-on-debian-8

  • So you have Java 8 as default now and solved your problem. – Samuel Philipp Mar 05 '19 at 11:31
  • 2
    Although those read like error messages, they are more like warnings. You can ignore them because the update-java-alternatives command has properly reconfigured the alternatives to enable all of the java components (including java and javac if its a jdk) to the desired version. @Kulfy made this comment below but it wasn't very obvious – Lee Meador Mar 06 '20 at 17:15
  • @Sancho, did you solve this issue? I have exatly the same problem on Ubuntu eoan. – codyLine Apr 20 '20 at 13:49
  • @codyLine - I am not sure... this happened some time ago. – sancho.s ReinstateMonicaCellio Apr 20 '20 at 14:54

2 Answers2

12

You can select the default Java Version by running the following command:

sudo update-alternatives --config java

Select the Java Installation you want to use per default by typing the selection number. Check the default Java Version by running java -version. It should print something similar to the following:

openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
  • 2
    It seems update-java-alternative does the same as update-alternatives --config java, and more. So I wouldn't expect this to solve the issue. Perhaps at best it doesn't attempt performing the actions which lead to the messages, but then it would possibly be not useful anyway. – sancho.s ReinstateMonicaCellio Mar 04 '19 at 23:17
  • Have you tried it? – Samuel Philipp Mar 05 '19 at 06:17
  • No. Would you mind posting the exact procedure to follow? How should I check if the ending result is ok (in addition to getting rid of the error message)? Please see updated OP; the actions implied by your command seem already executed by what I did. – sancho.s ReinstateMonicaCellio Mar 05 '19 at 10:40
  • @sancho.s If you want to check that if alternatives are changed, run java -version – Kulfy Mar 05 '19 at 11:17
  • @Kulfy - Already did that, I will add it. – sancho.s ReinstateMonicaCellio Mar 05 '19 at 11:22
  • I updated my answer. You can check the Java Version by running java -version. – Samuel Philipp Mar 05 '19 at 11:29
  • @sancho.s You can ignore those errors. IcedTea and Mozilla Java are just extra plugins. Java consists of many plugins. When you updated alternatives, it tried to update alternatives for that too but can't find those. They aren't required as well. So you can ignore those errors and consider them just as warnings. Your default java version is now JDK8. – Kulfy Mar 05 '19 at 11:52
0

jre-headless is okay if the java app you want to run has no gui.

sudo update-alternatives --config java

has potential inconsistent java env issue. See Setting JDK 7 as default

Tong Zhou
  • 101
  • 1