Gradle JAVA_HOME is set to an invalid directory

I have tried and looked at the past Gradle Java_HOME questions, however none of the options seems to work. I followed this website to install Gradle. However, all the Gradle commands I run result in the following error:

ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/jdk1.8.0_241
Please set the JAVA_HOME variable in your environment to match the location of your Java installation.

I'm also using OpenJDK 11 and

$ echo $JAVA_HOME
/usr/lib/jvm/jdk1.8.0_241
4

1 Answer

You can find java home by using the following command:

java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home' 

It will print something like:

java.home = /path/to/java_home

You can set the output of this command as JAVA_HOME by copying the path and adding the following line to your ~/.bashrc.

export JAVA_HOME=/path/to/java_home

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like