Link Search Menu Expand Document

Windows Command Line – Set Environment Variable

The windows command line or text interface is a kind of user interface that can be controlled by passing commands in the form of prompts instead of using a mouse. Command-line is different from GUI OS, i.e., Graphical User Interface Operating System. It only needs a keyboard to control and navigate by passing the commands instead of a mouse.

For example, to open the windows folder in the windows command line, we use “C:\Windows”.

However, using the command line requires one to remember lots of commands. However, it is very useful which should not be ignored. Command-line allows a user to perform all the tasks that they can perform on a GUI OS. And sometimes, there are many tasks that we can accomplish even quicker than GUI OS, and they are very easy to automate as well.

For example, if a person is asked to rename 50 files in a folder at a time. So, setting an environment variable with GUI can be very time-consuming but with the help of the windows command line, this can be done in seconds by passing a single command using a batch file or other scripts.

What is an Environment Variable?

An environment variable is a dynamic object that contains an editable value. It can be used by more than one software program in windows. The role of environment variables is to let the programs know which file directories to install, the location of temporary files, and the user profile settings. These are named environment variables because they shape the environment of the essential programs to run a computer.

How to set environment variables?

To set up an environment variable, the running system should have windows 10 OS. The user account should have admin privilege. It should also have access to Command Prompt or Windows PowerShell. Users can set up environment variables in two ways –

1.    Via GUI

To set up environment variable using GUI, the user should follow the following steps-

  • With the help of windows run, open System Properties.
  • Then select the Advanced option in the top menu and set Environment Variables.
  • The Environment Variables have two sections, user-specific and system-wide. So, to add a new environment variable, press the new button. Then, the user can add the variable according to their choice.

2.    Via Command Prompt

  • To set an environment variable with the help of a command prompt, use ‘setx’.
  • For example – setx [variable_name] “[variable_value]. Here, the variable name can be assigned the name of the variable you want to keep and value, the value you want to assign the variable.
  • Furthermore, if a user wants to add a system-wide environment variable, then use – setx [variable_name] “[variable_value]” /M.

Other useful articles:


Back to top

© , CMD Windows — All Rights Reserved - Terms of Use - Privacy Policy