[java] JAVA_HOME is set to an invalid directory:

I have set JAVA_HOME in my system C:\Program Files\Java\jdk1.8.0_ 131\bin; and I am trying to run cordova command( cordova build ) on command prompt, but I'm getting the error bellow. I have tried all the ways, but not able to resolve this issue:

ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk1.8.0_ 131\bin;

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

This question is related to java android cordova

The answer is


I am using using Ubuntu.

Problem for me solved by using sudo in terminal with the command.


After isntalling jdk please restart your system this works for me


You need to set with only C:\Program Files\Java\jdk1.8.0_12.

And check with using new cmd. It will be updated


JAVA_HOME should point to the home jdk directory, and not to jdk/bin directory.

You need to set the JAVA_HOME like this:

JAVA_HOME="C:\Program Files\Java\jdk1.8.0_131"

First try removing the '\bin' from the path and set the home directory JAVA_HOME as below: JAVA_HOME : C:\Program Files\Java\jdk1.8.0_131

Second Update System PATH:

  1. In “Environment Variables” window under “System variables” select Path
  2. Click on “Edit…”
  3. In “Edit environment variable” window click “New”
  4. Type in %JAVA_HOME%\bin

Third restart your docker.

Refer to the link for setting the java path in windows.


After setting the JAVA_HOME variable, run android studio as administrator


On Window 10, the problem was with the semicolon ;.

Go to edit the system environment variables and delete the semicolon at the end of JAVA_HOME value C:\Program Files\Java\jdk1.8.0_144

In other words, convert this C:\Program Files\Java\jdk1.8.0_12; to C:\Program Files\Java\jdk1.8.0_12

You might have to delete your entry in the Windows Dialog and create a new one. If you ever had multiple entries and get the bigger Form view, Windows automatically inserts a ; at the end of each entry, even if you only have one entry left.


You should set it with C:\Program Files\Java\jdk1.8.0_12.

\bin is not required.


Try the following:

  • Remove \bin from JAVA_HOME path.
  • Open new command line window.
  • Run your command as an administrator.

JAVA_HOME should be C:\Program Files\Java\jdk1.8.0_172 don't include semi-colon(;) or bin in path. Any jdk version above 7 will work. Also, you need to re-start the cmd


i think you need to remove the ';' from the end of the java path.


Remove the \bin, and also remove the ; at the end. After restart the cmd and run.


Please remove /bin and even semi colon ; from JAVA_HOME to resolve.


set JAVA_HOME as C:\Program Files\Java\jdk1.8.0_172

do not use semicolon ";" with above JAVA_HOME value

To verify that it is correctly set, Go to command prompt check for C:.......>sdkmanager --list

a complete list will appear that will let you now that it is successfully saved.

else it will show error that JAVA_HOME path is not correctly set.


I found this while googling the issue with android licences when installing Flutter.

For Linux, update Your ~/.bashrc (or other shell config) file by adding this line at the end:

JAVA_HOME=/usr/local/android-studio/jre

Note: I installed Android studio by following the official installation guide for Linux (link).

For Windows, use the android studio's path to the jre directory and update the environment variable with the right value.

Then, run flutter doctor --android-licenses and press y to review the licences which are not accepted. Press y for each of the licences. It will ask Accept? (y/N): at the end of the license file. After You accept all unaccepted licences, You should see:

All SDK package licenses accepted

Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to cordova

Why am I seeing net::ERR_CLEARTEXT_NOT_PERMITTED errors after upgrading to Cordova Android 8? Xcode couldn't find any provisioning profiles matching Cordova app not displaying correctly on iPhone X (Simulator) JAVA_HOME is set to an invalid directory: ionic 2 - Error Could not find an installed version of Gradle either in Android Studio cordova Android requirements failed: "Could not find an installed version of Gradle" Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK - Android Ionic 2: Cordova is not available. Make sure to include cordova.js or run in a device/simulator (running in emulator) Cordova : Requirements check failed for JDK 1.8 or greater Can't accept license agreement Android SDK Platform 24