How to fix the JAVA_HOME invalid directory error on a Mac

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

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 06/07/2023 at 17:05
Last Updated on 07/20/2023 at 16:42
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.

SubscribeDownload Open Source Kotlin Starter Project

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.
SubscribeContact UsVisit our BlogView our ServicesView our Work

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe