windows 如何从cmd永久更新系统PATH变量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24219627/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:37:08  来源:igfitidea点击:

How to update system PATH variable permanently from cmd?

windowspathcmd

提问by Nam G VU

We can use setxas discussed here.

我们可以setx这里讨论的那样使用。

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

But this command can just make changed to user PATH variable not the system one.

但是这个命令只能改变用户 PATH 变量而不是系统变量。

How can we make a similar system wide command?

我们如何制作一个类似的系统范围的命令?

enter image description here

在此处输入图片说明

回答by Hans Passant

Type setx /?to get basic command help. You'll easily discover:

键入setx /?以获取基本命令帮助。你会很容易发现:

/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 cmdshortcut and select Run as Administrator.

您需要从提升的命令提示符运行它。右键单击cmd快捷方式并选择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.

我们可能会破坏当前系统的 PATH 变量。请确保在修改之前备份其值。

回答by Nathan Julsrud

From powershell

来自 PowerShell

setx /M PATH "$($env:path);c:\program files\mynewprogram"