How to update system PATH variable permanently from cmd?

后端 未结 3 1608
一整个雨季
一整个雨季 2021-01-01 11:01

We can use setx as discussed here.

setx PATH \"%PATH%;C:\\Something\\bin\"

But this command can just make changed to user PATH

相关标签:
3条回答
  • Type setx /? to get basic command help. You'll easily discover:

    /M                     Specifies that the variable should be set in
                           the system wide (HKEY_LOCAL_MACHINE)
                           environment. The default is to set the
                           variable under the HKEY_CURRENT_USER
                           environment.
    

    You need to run this from an elevated command prompt. Right-click the cmd shortcut and select Run as Administrator.

    E.g.

    setx /M PATH "%PATH%;C:\Something\bin"
    

    Caution:

    We may destroy the current system's PATH variable. Make sure you backup its value before you modify it.

    0 讨论(0)
  • 2021-01-01 11:37

    From powershell

    setx /M PATH "$($env:path);c:\program files\mynewprogram"
    
    0 讨论(0)
  • 2021-01-01 11:43

    One problem with %PATH%, is it includes the user's path. If you don't mind Powershell, you can run the following

    $p = [Environment]::GetEnvironmentVariable("PATH", [EnvironmentVariableTarget]::Machine);
    [Environment]::SetEnvironmentVariable("PATH", $p + ";C:\MyPath", [EnvironmentVariableTarget]::Machine);
    
    0 讨论(0)
提交回复
热议问题