Skip to content
This repository was archived by the owner on Nov 17, 2022. It is now read-only.
This repository was archived by the owner on Nov 17, 2022. It is now read-only.

JAVA_HOME variable setup script on linux not compatible with Java-14 #1907

Open

Description

@trane77

Please, tell us what's the problem?

[x] Wrong documentation
[x] Improvement of existing article

Please, tell us more details

Currently the docs are telling to set the JAVA_HOME variable this way:

export JAVA_HOME=$(update-alternatives --query javac | sed -n -e 's/Best: *\(.*\)\/bin\/javac/\1/p')

This can work, but not always: in a system where Java 14 is installed, then it will be reported as the "best" option, which in turn will not be compatible with Nativescript as it supports Java >= 8 and <= 13. "Best" is the most recent version .

I've found a good script, which is working fine, it depends on which version the user selects from update-alternatives:

#!/bin/bash
if [ -z "${JAVA_HOME}" ]
then
    JAVA_HOME=$(readlink -nf $(which java) | xargs dirname | xargs dirname | xargs dirname)
    if [ ! -e "$JAVA_HOME" ]
    then
        JAVA_HOME=""
    fi
    export JAVA_HOME=$JAVA_HOME
fi

To switch the default java version to be used:

sudo update-alternatives --config java
sudo update-alternatives --config javac

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions