Intellij Gradle terminal ERROR: JAVA_HOME is not set

18,294

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.

Share:
18,294
hoobaka
Author by

hoobaka

Java developer interested in all things devops, Java, and AWS.

Updated on July 07, 2022

Comments

  • hoobaka
    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
    hoobaka over 7 years
    Thanks. Working on windows system so changed 'export' to 'set' and all was well.
  • Klinki
    Klinki over 7 years
    This answer is platform specific to Windows and I don't see original question mentioning OS.
  • Dmitry Smolyaninov
    Dmitry Smolyaninov over 3 years
    So what? It helped many people better than accepted one.
  • D.M.
    D.M. about 3 years
    Don't forget to restart your Idea/Android Studio after this.