How to set environment variables PATH and JAVA_HOME to use Android Studio's JDK in Terminal

Tadashi Shigeoka ·  Sat, April 20, 2019

I’ll introduce how to set the environment variables PATH and JAVA_HOME so you can use Android Studio’s JDK in Terminal.

Android Studio

Prerequisites

  • Android Studio (3.4) installed
  • Java not separately installed

⚠️ No Java runtime present, requesting install.

$ ./gradlew clean build
No Java runtime present, requesting install.

If you get this message, the JDK PATH is not set, so you need to configure PATH and JAVA_HOME.

How to Configure Android Studio's JDK for CLI Use

Simply add the following to .bashrc or .zshrc to set the PATH and JAVA_HOME environment variables:

export PATH=$PATH:/Applications/"Android Studio.app"/Contents/jre/jdk/Contents/Home/bin
export JAVA_HOME=/Applications/"Android Studio.app"/Contents/jre/jdk/Contents/Home

After modification, use the source command to apply the changes and load the environment variables.

source ~/.zshrc

That’s all from the Gemba, where we want to use Android Studio’s JDK in Terminal as well.