How to set environment variables PATH and JAVA_HOME to use Android Studio's JDK in Terminal
I’ll introduce how to set the environment variables PATH and JAVA_HOME so you can use Android Studio’s JDK in Terminal.
$ ./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.
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.