Set PATH and other environment variables in Windows 10

by Remy Pereira on 12th September 2016

In older windows systems you had to navigate to Advanced System Settings in Control Panel to view, edit or add environmental variables.

  • Windows XP - Right-click My Computer, and then click Properties → Advanced → Environment variables → Choose New, Edit or Delete.
  • Windows 7 - Click on Start → Computer → Properties → Advanced System Settings → Environment variables → Choose New, Edit or Delete.

In Windows 8 and 10, you can navigate to Advanced System Settings in a similar way.

  • Windows 8 - Right click on bottom left corner to get Power User Task Menu → Select System → Advanced System Settings → Environment variables → Choose New, Edit or Delete.
  • Windows 10 - Right click on Start Menu to get Power User Task Menu → Select System → Advanced System Settings → Environment variables → Choose New, Edit or Delete.
    Power user task menu

However, in Windows 10 you can directly get to the Environment Variables window using Search the web and Windows box next to the Start menu. Type environment variables in Windows Search box which gives you two options in search results:

  • Edit the system environment variables
  • Edit environment variables for your account.

Choose either option and you can add, edit or delete environment variables like PATH.

Edit Environment variables
System Advanced Options
Environment variables

Set environment variables from command prompt

You can set environment variables from Windows Command Prompt using the set or setx command. The set command only sets the environment variable for the current session. The setx command sets it permanently, but not for the current session. If you want to set it for current as well as future sessions, use both setx and set.

For example, you can set the PATH environment variable permanently (current and future sessions) as below:


C:\>setx PATH "C:\myfolder;%PATH%"

SUCCESS: Specified value was saved.

C:\>set PATH=C:\myfolder;%PATH%	

To view the current path, run:

C:\>echo %PATH%

Note:

  1. By default setx sets the variable in the local environment (Under HKEY_Current_User Registry key). If you want to set the system variable (Under HKEY_LOCAL_MACHINE registry key), use the flag /m. Start the command prompt as administrator on Windows 10, right click on Start menu and select Command Prompt(Admin).
    C:\>setx /m PATH "C:\myfolder;%PATH%"
    
    SUCCESS: Specified value was saved.
    
    
  2. The maximum value allowed for a enviroment variable is 1024 characters. So if your variable is long and you try to append to it with setx, you may get a truncated result.
    C:\>setx PATH "C:\myfolder;%PATH%"
    
    WARNING: The data being saved is truncated to 1024 characters.
    
    SUCCESS: Specified value was saved.
    

Set environment variable by Registry edit

If your PATH variable is too long, then the best method would be to edit the registry.

For user environment variables, change the key HKEY_CURRENT_USER\Environment. For System Environment variables change

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

Add, Edit or Delete the environment variable you want to change, then reboot to activate the changes.


Post a comment

Comments

Mitz | December 13, 2022 10:50 AM |

Is there a way to set the environmental variable path to be the first one in the list via group policy specifically?

Cliffclof | February 20, 2022 12:16 PM |

I think it should be setx PATH "%PATH%;C:\myfolder" to avoid phantom closures?

Gilu | February 17, 2022 6:22 AM |

Dont use `setx` in case of many paths previously set: `WARNING: The data being saved is truncated to 1024 characters.`

Karl Horky | October 6, 2019 3:00 PM |

@Remy it seems like the examples above are still using "path1" - were they not updated after all? A bit confusing having them like this...

Karl Horky | October 10, 2019 10:35 AM |

Great thanks Remy!

Remy | October 6, 2019 4:41 PM |

my bad,i updated only in one place :)..should be ok now.

J. | October 24, 2018 3:34 PM |

Why are you setting "path1" in the set and setx examples? Is that a typo or?

Karl Horky | October 6, 2019 2:59 PM |

@Remy it seems like the examples above still use "path1"... was this not updated?

Remy | October 26, 2018 12:46 PM |

sorry that was a typo, thanks for pointing it out. Article updated now.

Abhishekachar M | September 19, 2019 2:44 PM |

Sir,how to restore deleted path because I accidentally deleted it. In registry also I couldn't find the deleted path

Evans | September 20, 2019 11:18 AM |

you could add the path again if you know what was in there. if you don't remember then only option will be a full system restore from backup. good luck!!

Raisa | October 25, 2016 3:16 PM |

LongPathTool a software will let you easily delete, copy or rename long path files. It worked for me. Must Try Once