DEV Community

Hermione2408
Hermione2408

Posted on • Edited on

Set env variables in Windows at one go

What is Environment Variable and Why do we need it?

Environment Variables in Windows
Environment Variables contain a value that can change, depending on conditions or on information passed to the program. They are information containers for all applications running on the operating system which helps to set up the software environment.

It provides ease in searching.Instead of going through the entire system, the environment variable contains valuable information about system processes, configuration data, file path, and more.

In Windows to set all the env variable at one go

  • Create a Bash file using the .bat extension eg setenv.bat.

  • In the bash file use the following syntax for setting the env variable.

setx [variable_name] “[variable_value]”
Enter fullscreen mode Exit fullscreen mode

Here:
[variable_name] - name of the variable you want to enter.
[variable_value] - value for the created variable.

For example, let’s add a APP_NAME with a value “ABC” in bash file:

setx APP_NAME "ABC"
Enter fullscreen mode Exit fullscreen mode
  • After creating the bash file To set the env variable in one go We can use the following command in the command prompt
setenv.bat 
Enter fullscreen mode Exit fullscreen mode

To set env variable individually

You can set each env by using the following command in command prompt

setx APP_NAME "ABC"
Enter fullscreen mode Exit fullscreen mode

Verify its existence

To verify its existence using Command Prompt. We can use the following command:

Set APP_NAME 
// ABC 
Enter fullscreen mode Exit fullscreen mode

Or you can see the set env variables through the following path in windows:

Control Panel -> System and Security -> System -> Advance System Setting-> Environment variables

Verify set env variable

Top comments (1)

Collapse
 
shvmsrma_94 profile image
Shivam Sharma

Great read!