13

Hello fellow Ubuntu users,

I am trying to learn how to write modifications to Minecraft. In order to follow the tutorial I am using, I need to run a "gradlew". The command is as follows

./gradlew setupDecompWorkspace eclipse

This yields the following

ERROR: JAVA_HOME is set to an invalid directory: /usr/local/java/jdk1.8.0_20

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Obviously I don't know what to do or even what this means. Any help is much appreciated.

| improve this question | | | | |
31

Before running the command try entering:

export JAVA_HOME="path_to_java_home"

Where path_to_java_home is the folder where your bin/java is.

If java is properly installed you can find it's location, by using the command:

readlink -f $(which java)

Don't forget to remove bin/java from the end of the path while putting it into JAVA_HOME

| improve this answer | | | | |
  • Okay, I did what you said, however, it yields the same results except the path has changed. – Joseph_carp Nov 27 '14 at 21:09
  • 1
    If you run $JAVA_HOME/bin/java -version after export, does it work fine showing the java version? – Andrew Onischuk Nov 27 '14 at 21:11
  • $JAVA_HOME/bin/java -version yields bash: /usr/local/java/jdk1.8.0_20/bin/java: No such file or directory – Joseph_carp Nov 27 '14 at 21:13
  • 2
    seems like your export is wrong. Please show export command you used. And also show the readlink -f $(which java) output – Andrew Onischuk Nov 27 '14 at 21:14
  • 5
    you should set it to the folder where bin/java is meaning export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64/jre" not export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java" – Andrew Onischuk Nov 27 '14 at 21:20
13

To make it automatic on Linux/Ubuntu, add these lines at the end of your .bashrc:

JAVA_HOME=$(dirname $( readlink -f $(which java) ))
JAVA_HOME=$(realpath "$JAVA_HOME"/../)
export JAVA_HOME

This gets java executable, then climbs up a directory level

To designate the default java version/executable on Debian/Ubuntu, run this once:

sudo update-alternatives --config java

This builds up on previous answer by Andrew Onischuk (thanks!)

| improve this answer | | | | |
  • Its work like a charm. It solved my problem after 3 days. – Hitesh Sarsava Sep 17 '19 at 10:11
1

Try to edit /usr/bin/gradle

Comment the line "export JAVA_HOME=/usr/lib/jvm/default-java" with a #

this: #export JAVA_HOME=/usr/lib/jvm/default-java

| improve this answer | | | | |
1

Get your Java path using the command

whereis java

The following is a possible output depending on your default Java version

java: /usr/bin/java /usr/share/java /usr/lib/jvm/jdk1.8.0_241/jre/bin/java

Maven need to pick the Java location (home) so you can export the Java path using the following command

export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_241/jre

This will allow Maven to pick the java version and location in the /etc/environment file

Optionally you can add this in the /etc/environment manually using the following command

sudo nano /etc/environment

and edit the JAVA_HOME=/usr/lib/jvm/jdk1.8.0_241/jre/

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.