hoobaka
hoobaka

Reputation: 155

Intellij Gradle terminal ERROR: JAVA_HOME is not set

In IntelliJ IDEA, using the Gradle window I am able to execute any and all Gradle tasks. However, when I try and execute the same tasks through the terminal window within the IDE, it hits me with the following error:

ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

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

This occurs when using gradle and gradlew. In IntelliJ -> File -> Project Structure -> Project then SDK is set correctly to 1.8. Any suggestions for resolving this so I can use the terminal to execute Gradle tasks would be greatly appreciated.

Upvotes: 11

Views: 33572

Answers (3)

Liker
Liker

Reputation: 2267

My answer is for the case when Ubuntu app is installed over Windows. So in Windows, I can run Ubuntu terminal. My Android Studio is installed on Windows. And I try to run gradle from the Ubuntu terminal. I tried to set up JAVA_HOME to multiple addresses via Ubuntu terminal: export JAVA_HOME=/mnt/c/... But nothing helped, including java address provided by Ubuntu ("whereis java" command): /usr/share/java

Then I merely did the same using Windows terminal (Command Prompt). And gradle worked.

Upvotes: 0

Imesh Chamara
Imesh Chamara

Reputation: 181

go to Java installation (C:\Program Files\Java\jdk ********) and copy the address file. Right click the "my computer" select "Properties" or go to "Control Panel > System and Security > System". Select "Advanced system settings" then click the "Environment Variables" button. Click System Variables, New write Variable Name to "JAVA_HOME" and write Variable Value to Java installation folder address then click OK finish it.

Upvotes: 15

davesbrain
davesbrain

Reputation: 606

You need an environment variable set for this to work. You can simply type in the command line:

export JAVA_HOME=<PATH to your Java Home>

Or you can put that line in your .rc file. On a mac you can do this:

export JAVA_HOME=`/usr/libexec/java_home`

More information can be found here: http://javarevisited.blogspot.com/2012/02/how-to-set-javahome-environment-in.html

Upvotes: 5

Related Questions