How to Set Environment Variable Temporarily using Command Prompt in Microsoft Windows
Introduction
As the description in the article, the content will be focus on how to set an environment variable temporarily. The process for defining or setting the environment variable will use a Command Line Interface exist in a device using Microsoft Windows as its operating system. In Microsoft Windows, Command Prompt is the tool act as a Command Line Interface where the command execution takes place.
Set Environment Variable Temporarily using Command Prompt in Microsoft Windows
In this section, it will describe in detail the step for setting the environment variable temporarily. Basically, it is just using a simple command with the proper format. Below is the step to do it :
-
Run the Command Prompt as the Command Line Interface exist in a device running using Microsoft Windows. The following is the display of the running Command Prompt :
Microsoft Windows [Version 10.0.22631.4037] (c) Microsoft Corporation. All rights reserved. C:\Users\Personal>
-
After the Command Prompt appear, type the command for setting environment variable temporarily. The format for setting environment variable temporarily is ‘ set ENVIRONMENT_VARIABLE_NAME=”value” ‘. As for an example, it will use JAVA_HOME environment for further demonstration.So, type the following command :
Microsoft Windows [Version 10.0.22631.4037] (c) Microsoft Corporation. All rights reserved. C:\Users\Personal> set JAVA_HOME="C:\Program Files\Java\jdk-17.0.2"
-
Finally, test back the JAVA_HOME environment variable. It is important just for checking the value of it. In order to do that, print the content of the JAVA_HOME environment variable. Below is how to be able to do that in the exact same Command Prompt :
Microsoft Windows [Version 10.0.22631.4037] (c) Microsoft Corporation. All rights reserved. C:\Users\Personal> set JAVA_HOME="C:\Program Files\Java\jdk-17.0.2" C:\Users\Personal> echo %JAVA_HOME% "C:\Program Files\Java\jdk-17.0.2" C:\Users\Personal>
-
Last but not least, open or run another Command Prompt. In this second Command Prompt, type or print the JAVA_HOME environment variable. It will print or display the different value printed in the first Command Prompt defined before. It will not print ‘”C:\Program Files\Java\jdk-17.0.2″‘. It will print whatever value the JAVA_HOME environment variable had before in the first place.
Take a look in the following video below just to be able to see how to do it as an actual additional reference :