Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA_HOME is set to an invalid directory while running ./gradlew on OSX

I tried running ./gradlew from an Android project directory, but I get an error of:

ERROR: JAVA_HOME is set to an invalid directory: /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home

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

Things I've tried:

  1. Navigated to /Library/Java/JavaVirtualMachines. jdk1.8.0_11.jdk exists, but so does jdk1.7.0_79.jdk

  2. which java prints out /usr/bin/java

  3. printenv prints

...

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home JDK_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home

...

  1. javac -version prints javac 1.8.0_11

  2. which javac prints /usr/bin/javac

like image 780
EGHDK Avatar asked Dec 17 '15 04:12

EGHDK


People also ask

How do you fix please set the Java_home variable in your environment to match the location of your Java installation?

To set JAVA_HOME, do the following: Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1.

What is Java_home on Mac?

The JAVA_HOME environment variable points to the file system location where the JDK or JRE was installed in your system. You can specify the path according to the location where Java is installed in your system. For MAC OSX it is: /Library/Java/Home.

Where is my Java Path Mac?

In macOS, the JDK installation path is /Library/Java/JavaVirtualMachines/jdk-10. jdk/Contents/Home . The root directory of the JDK software installation.


1 Answers

Check if /usr/libexec/java_home exists. If it does then try running

export JAVA_HOME=`/usr/libexec/java_home` 

and rerunning your gradlew build. If it works then make it permanent with

echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile 
like image 130
lodlock Avatar answered Sep 23 '22 21:09

lodlock