Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to find 'JAVA_HOME' environment variable in Mac

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.

like image 805
ToniTJK Avatar asked Mar 28 '18 09:03

ToniTJK


People also ask

Where is the JAVA_HOME environment variable Mac?

JAVA_HOME is essentially the full path of the directory that contains a sub-directory named bin which in turn contains the java. For Mac OSX – it is /Library/Java/Home.

Why JAVA_HOME is not working?

Verify JAVA_HOME Enter the command echo %JAVA_HOME% . This should output the path to your Java installation folder. If it doesn't, your JAVA_HOME variable was not set correctly. Please make sure you're using the correct Java installation folder, or repeat the steps above.

How do you fix please set the JAVA_HOME variable in your environment to match the location of your Java installation?

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.


1 Answers

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

You have to do it like following:

  • 10 JDK 8 Installation for OS X

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.

like image 105
catch23 Avatar answered Oct 22 '22 06:10

catch23