update-java-alternatives failed to create default-java simlink

Asked by SiKing

Running on Ubuntu server bionic.
I installed: `sudo apt install java-common openjdk-8-jdk groovy`.
I then run `sudo update-java-alternatives --set java-1.8.0-openjdk-amd64`.
But when I run `groovy --version`, I get error: "groovy: JAVA_HOME is not defined correctly, can not execute: /usr/lib/jvm/default-java/bin/java".
I was under the impression that update-java-alternatives would create the /usr/lib/jvm/default-java simlink, but it is missing. Am I wrong? Am I missing something?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu java-common Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

Is it listed if you run:
sudo update-alternatives --config java

Revision history for this message
Manfred Hampl (m-hampl) said :
#2

For diagnostic purposes, what is the output of the commands

uname -a
lsb_release -crid
echo $JAVA_HOME

Revision history for this message
SiKing (mark-lehky) said :
#3

swarm@hive:~$ uname -a
Linux hive 4.15.0-46-generic #49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
swarm@hive:~$ lsb_release -crid
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
swarm@hive:~$ echo $JAVA_HOME

swarm@hive:~$

Revision history for this message
SiKing (mark-lehky) said :
#4

swarm@hive:~$ sudo update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
Nothing to configure.

Revision history for this message
Manfred Hampl (m-hampl) said :
#5

Don't confuse the symbolic link /usr/bin/java and the environmental variable JAVA_HOME!

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#6

What is the output of:

apt-cache java-common openjdk-8-jdk groovy

Thanks

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#7

We can install Sun Java if you like. WebUpd8 has a PPA to make installing and setting it up easily

Revision history for this message
SiKing (mark-lehky) said :
#8

"Don't confuse the symbolic link /usr/bin/java and the environmental variable JAVA_HOME!"
I don't understand? what is the confusion?

If I manually create the simlink `ln -s /usr/lib/jvm/java-1.8.0-openjdk-amd64 /usr/lib/jvm/default-java` then everything works fine. I cannot even remember the last time I had to fiddle around with JAVA_HOME.

Please note: I am *not* asking how to configure my Java. My question is: Is the command update-java-alternatives supposed to create the default-java simlink?

Revision history for this message
SiKing (mark-lehky) said :
#9

"We can install Sun Java if you like. ..."

I am aware of the WebUpd8 PPAs, however I am not interested in running Sun Java.

Revision history for this message
Best Manfred Hampl (m-hampl) said :
#10

It seems to me that groovy tries to find java either by using the JAVA_HOME environment variable, or - if that is not set - in the location /usr/lib/jvm/default-java/bin/java

On a standard Ubuntu bionic system the file (link) /usr/lib/jvm/default-java is provided by the package default-jre-headless and points to files from the package openjdk-11-jre-headless

I assume: If you use the default java version for Ubuntu bionic (which meanwhile has been changed to 11) including the default-jre-headless package, then the link would be automatically set and groovy would work without error message (and without setting JAVA_HOME).

Revision history for this message
SiKing (mark-lehky) said :
#11

Thanks Manfred Hampl, that solved my question.