How to set an environment variable in Windows 10

James Walker

Updated on:

Windows 10 Logo Generic Featured Image Hero

Environment variables are global values used to configure programs running on your PC. Although they sound technical, they’re really just a shared configuration store for different apps to hook into.

Environment variables are tied to individual user accounts, so different users can have different configurations. There are also global system variables, such as “%windir%”, which always points to the directory where Windows is installed (e.g. “C:Windows”). Instead of hardcoding this value, apps can instead reference “%windir%” when they need to access the Windows directory.

Editing environment variables in Windows 10

Many apps add their own environment variables after installation. To view and edit your environment variables, search for “edit environment variables” in the Start menu and select the result which appears.

Here, you can see all the environment variables which have been set on your machine. In the example above, you can see the “OneDrive” variable points to the OneDrive storage directory for the current user – if you change the OneDrive directory from the OneDrive system tray, this value will update accordingly.

Editing environment variables in Windows 10

Because OneDrive is an environment variable, programs can get the location of your OneDrive directory using “%OneDrive%” in paths. You can even try this out yourself – press Win+R to open the Run prompt and type “%OneDrive%” to open your OneDrive folder.

To edit an environment variable, select it from the list and click “Edit.” Use the popup prompt to change the variable’s name and value. However, take care when editing variables you didn’t create – an incorrect value could prevent a program, or the entire system, from running properly.

Viewing environment variable in Command Prompt in Windows 10

Creating a new variable is a similarly simple affair – click the “New” button and fill out the name and value. Remember though that environment variables do nothing on their own. Since no program will use your variable, it will have no effect. However, you can get the value of your environment variable using the Command Prompt – launch it from the Start menu and type “echo %<myvariable>%”, replacing “<myvariable>” with your variable’s name, to see its value displayed.