Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I installed Android Studio 4.1 and trying to run existing project. But it gives error like this:

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. 
like image 488
Khamidjon Khamidov Avatar asked Oct 14 '20 18:10

Khamidjon Khamidov


People also ask

How do you fix error JAVA_HOME is not set and no Java command could be found in your path?

Download Liberica JDK and on installation it will automatically set JAVA_HOME environment variable. Now you just go to Android Studio -> Project Structure -> SDK -> Point all jdk path to liberica jdk installation directory and apply. You are done. Just restart android studio and gradle command will work.

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 happens if JAVA_HOME is not set?

If any program that requires a Java runtime fails to find the JAVA_HOME environment variable upon startup, or if the JAVA_HOME environment variable is misconfigured, it will result in some of the following error messages to be displayed: A Java installation exists but JAVA_HOME has been set incorrectly.


1 Answers

You have to set the JAVA_HOME Environment Variable.

On Windows, I solved the issue as follows:

  1. Download the Java JDK from here and install it. (This links to version 15, which requires you to create an account in order to download. Version 16 is available to download without creating an account, but it has caused me an error that required me to downgrade.)

  2. Set the "JAVA_HOME" Environment Variable:

    • Open Windows Search, type in “env”, and choose “Edit the system environment variables”.

      enter image description here

    • Click on "Environment Variables...".

    • Click on "New".

    • Fill in the "variable name" field with "JAVA_HOME".

    • Fill in the "variable value" with the path to where Java is installed on your computer. (for me it was under "C:\Program Files\Java\<jdkversion>")

      Screenshot

    • Click "OK" and close all dialogs.

  3. Restart your IDE / Terminal. (do not skip this step)

like image 79
MendelG Avatar answered Sep 21 '22 12:09

MendelG