Windows CMD – Set JAVA_HOME Variable Using Command Prompt

This post shows you how to set JAVA_HOME environment variable using Windows CMD (Command Prompt).


1. Open CMD as administrator

First, we need to open CMD as administrator like this.

Open Windows CMD Command Prompt


2. Set JAVA_HOME variable

Then use the following command to set JAVA_HOME variable.

setx JAVA_HOME "path/to/your/java/jdk" /M

For example, we set “C:\Program Files\Java\jdk1.8.0_92” to JAVA_HOME.

Set JAVA_HOME using command line


3. Check JAVA_HOME variable

Now open another CMD and use echo %JAVA_HOME% command to check whether we did it right or not.

echo JAVA_HOME path using cmd

We are done!

0 0 vote
Article Rating
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x