How to Set Temporary Environment Variable using Command Prompt in Microsoft Windows

Posted on

How to Set Temporary Environment Variable using Command Prompt in Microsoft Windows

Aside from using Power Shell for setting environment variable temporarily, there is another way to do that. Normally, it actually can be done using Command Prompt. It is also quite simple. Defining an environment variable is important if there is a need to use it further. Especially for more process later on in the next command execution in the same Command Prompt.

Table of Contents

Introduction

Just define the environment variable directly by using the Command Prompt. It is possible by just typing a certain format. Definitely, it is different with the one or the format for defining environment variable using Power Shell. In order to look out on how to do it with the Power Shell, just check the article with the title of ‘How to Set Temporary Environment Variable using Power Shell in Microsoft Windows‘ which also exist in this link.

How to Set Temporary Environment Variable using Command Prompt in Microsoft Windows

In order to use Command Prompt, just run it. Below are the steps for doing it :

  1. As in the first step, running Command Prompt is possible just by pressing the Start button, filling the textfield search appear by typing ‘Command Prompt’ until the link for running Command Prompt appear.

  2. Just make sure to click the correct link. If it is a correct one which has the label of ‘Command Prompt’, it will run the Command Prompt with the following appearance :

    How to Set Temporary Environment Variable using Command Prompt in Microsoft Windows
    How to Set Temporary Environment Variable using Command Prompt in Microsoft Windows
  3. For defining or setting an environment variable in a Command Prompt, below is the pattern or the format for doing it :

    set $ENVIRONMENT_VARIABLE_NAME=ENVIRONMENT_VARIABLE_VALUE

    For an example, below is the process for defining or setting an environment variable with the value of a certain path location. The example is defining the path of Gitlab repository path location as follows :

    Microsoft Windows [Version 10.0.22621.2715]
    (c) Microsoft Corporation. All rights reserved.
    
    C:\Users\Personal>set GITLAB_HOME=C:\Users\Personal\Documents\Gitlab.

Checking the Environment Variable

The previous section is just running the Command Prompt,  setting or defining the environment variable. Following after, just check the value or the content of the environment variable :

  1. Basically, just make sure that the previous Command Prompt executed is still running. In other words, the one where it contain the definition or the assignment process of the environment variable.  Below is the appearance of the Command Prompt will look like :

    Microsoft Windows [Version 10.0.22621.2715]
    (c) Microsoft Corporation. All rights reserved.
    
    C:\Users\Personal>set GITLAB_HOME=C:\Users\Personal\Documents\Gitlab
    
  2. Just continue on the process above for typing a command which is going to print the environment variable. Prove that the value of the environment variable is correct. It is helpful just for checking the syntax for defining the environment variable is also correct in the Command Prompt :

    Microsoft Windows [Version 10.0.22621.2715]
    (c) Microsoft Corporation. All rights reserved.
    
    C:\Users\Personal>set GITLAB_HOME=C:\Users\Personal\Documents\Gitlab
    C:\Users\Personal>echo %GITLAB_HOME%
    C:\Users\Personal\Documents\Gitlab
    
    C:\Users\Personal>
    

    As in the output of the command for showing or printing the content of the environment variable above, setting or defining the environment variable in the previous section is a correct one.

For more information, just click in the following link in order to view how to be able to do it. Furthermore, just check the video embedded as follows :

 

Leave a Reply