Intellij Gradle terminal ERROR: JAVA_HOME is not set
Solution 1
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
Solution 2
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.
hoobaka
Java developer interested in all things devops, Java, and AWS.
Updated on July 07, 2022Comments
-
hoobaka almost 2 years
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.
-
hoobaka over 7 yearsThanks. Working on windows system so changed 'export' to 'set' and all was well.
-
Klinki over 7 yearsThis answer is platform specific to Windows and I don't see original question mentioning OS.
-
Dmitry Smolyaninov over 3 yearsSo what? It helped many people better than accepted one.
-
D.M. about 3 yearsDon't forget to restart your Idea/Android Studio after this.