Or use Start -> Edit the system environment variables -> Environment variables. Setx JAVA_HOME 'E:\Program Files\Java\jdk1.8.0_251' For me path to JDK is E:\Program Files\Java\jdk1.8.0_251. Open Command Prompt ( Win+R, type cmd and press Enter) or use any other terminal you like.
This is the step-by-step note that answering the question: How to install and launch Android emulator without installing Android Studio itself.