How to fix the JAVA_HOME invalid directory error on a Mac

Oscar de la Hera Gomez
A flower that represents Android Studio. Beneath it sits the text "Fix JAVA_HOME invalid directory error."

A step by step MacOS guide on fixing the ERROR: JAVA_HOME is set to an invalid directory in Android Studio.

The following tutorial aims to walk you through how to fix the error shown below.

A screenshot of Terminal in Android Studio showing the JAVA HOME Invalid Directory Error.

Step One: Find the location of the Android Studio Java folder

A screenshot of Finder showing the location of the Java Home folder within the Android Studio package.

In order to set the correct path, you must use Finder to find the location of the Java folder.

A | Go to Applications

A screenshot of Finder on the Applications tab.

Open Finder and go to Applications

B | Show Android Studio Package Contents

A screenshot of Android Studio in Finder. Highlighted is the "Show Package Contents" tab that exists in the menu that appears when you right click Android Studio in Finder.

Right Click Android Studio and click Show Package Contents.

C | Locate the Java Home Folder

A screenshot of Finder showing the location of the Java Home folder within the Android Studio package.

Navigate the Package Contents to find the location of the Java Home folder.

Past locations include:

  • /Applications/Android\ Studio.app/Contents/jre/Contents/Home
  • /Applications/Android\ Studio.app/Contents/jbr/Contents/Home

Step Two: Set JAVA_HOME

A screenshot of Terminal showing you how to set the new Java Home.

In Terminal, run the line below replacing PATH_TO_JAVA_HOME, with the path that you uncovered in Step One (i.e /Applications/Android\ Studio.app/Contents/jbr/Contents/Home).

export JAVA_HOME="PATH_TO_JAVA_HOME"

Please note that for changes to take effect you will have to restart Android Studio or run the line above within the Android Studio Terminal.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details