Failed to find 'JAVA_HOME' environment variable in Mac
Asked Answered
B

1

11

I'm new on Mac, so I installed Cordova (Node, Git, Grandle) but I can't execute it in my mobile phone, I mean I can't do "sudo Cordova run android" because it can't find "JAVA_HOME". When I installed I put this variable before... (It is a headache πŸ€•)

I tried to open the bash_profile but I didn't find it and if I open in terminal it always open a new file.

If I do echo $JAVA_HOME, it is the result:

echo $JAVA_HOME

/usr/libexec/java_home

And this is my error:

sudo cordova run android --target=ZY223T38PM

(node:1369) UnhandledPromiseRejectionWarning: CordovaError: Failed to find 'JAVA_HOME' environment variable. Try setting setting it manually. at /Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/lib/check_reqs.js:185:35 at _rejected (/Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:864:24) at /Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:890:30 at Promise.when (/Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:1142:31) at Promise.promise.promiseDispatch (/Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:808:41) at /Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:624:44 at runSingle (/Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:137:13) at flush (/Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:125:13) at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickCallback (internal/process/next_tick.js:180:9) (node:1369) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:1369) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Bellyband answered 28/3, 2018 at 9:19 Comment(9)
set up JAVA_HOME to point to the directory where your JAVA installation resides and then try – Jotunheim
what is output after executing java -version in terminal? – Catharina
@nazar_art It says that I need to install JDK, but I swear I installed it, well I am going to install it and say something – Bellyband
@nazar_art I have Android Studio and it functions perfectly with java, and have sdk... so I don't understand. – Bellyband
now it says that it require jdk 1.8 or greater but I installed the salt version – Bellyband
Why are git and cordova tagged in this? – Hydrous
set JAVA_HOME environment variable which points to the directory where Java is installed and then try again. – Hedonic
Someone know about this error? (node:8132) UnhandledPromiseRejectionWarning: Error: spawn EACCES – Bellyband
@Hydrous because the project I'm trying to run is doing with Cordova, git and node. – Bellyband
C
12

You didn't install JAVA_HOME correctly, therefore it fails.

You have to do it like following:

After installation you have to add installed java to system variable:

Run in terminal for verification:

java -version

The output should be something like:

java version "1.8.0_06-ea"
Java(TM) SE Runtime Environment (build 1.8.0_06-ea-b13)
Java HotSpot(TM) 64-Bit Server VM (build 23.2-b04, mixed mode)

After this check, you can import java to your IDE.

Catharina answered 28/3, 2018 at 9:46 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.