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

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

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest