In the dynamic world of Windows 10, setting environment variables via the command line can significantly streamline your workflow. Whether you're a developer, a power user, or simply someone who likes to automate tasks, knowing how to set environment variables can save you time and effort. This guide will walk you through the process, making it as simple and straightforward as possible.
Understanding Environment Variables
Before we dive into the command line, let's briefly understand what environment variables are. In computing, an environment variable is a dynamic value that can affect the way running processes behave on a computer. They are typically used to configure the operating system, applications, or shells. In Windows 10, you can set environment variables for the current session, the current user, or for the entire system.
Setting Environment Variables in Windows 10 Command Line
To set environment variables in Windows 10 using the command line, you'll primarily use the `set` command in the Command Prompt (cmd) or PowerShell. Here's how you can do it:

Setting a Temporary Environment Variable
To set an environment variable that lasts only for the current command session, use the following syntax:
set VARIABLE_NAME=VALUE
For example, to set a temporary variable named "MY_VAR" with the value "Hello, World!", you would type:
set MY_VAR=Hello, World!
Setting a Permanent Environment Variable
To set an environment variable that persists even after you close the command prompt or restart your computer, you'll need to modify the system's environment variables. Here's how:

- Right-click on the Start button and select "System".
- Click on "Advanced system settings" in the left-hand menu.
- In the "System Properties" window, click on "Environment Variables..." at the bottom.
- Under "System variables", click on "New..." to create a new variable.
- Enter the variable name and value, then click "OK".
- Click "OK" on all windows to save your changes.
Viewing Environment Variables
To view the current environment variables in your command line session, use the following commands:
- In Command Prompt:
set - In PowerShell:
Get-ChildItem Env:
Using Environment Variables in Batch Scripts
When writing batch scripts, you can use environment variables to make your scripts more dynamic and versatile. To use an environment variable in a batch script, prefix the variable name with a percent sign (%), like this:
echo %MY_VAR%
This will print the value of the "MY_VAR" environment variable.
Best Practices
When working with environment variables, it's essential to follow some best practices:
- Use descriptive variable names to make your scripts easier to understand and maintain.
- Be cautious when modifying system-wide environment variables, as they can affect all users and applications on your computer.
- Consider using tools like Chocolatey or Scoop to manage environment variables and other system configurations.
Setting environment variables in Windows 10 command line can greatly enhance your productivity and automation capabilities. By following the steps outlined in this guide, you'll be well on your way to mastering this essential skill. Happy coding!