如何在从 nodejs.org 下载的 nodejs 文件夹之外执行 运行 'node' 和 'npm' 命令
How to run 'node' and 'npm' commands outside of the nodejs folder that was downloaded from nodejs.org
所以,我在电脑上安装了node.js,并将nodejs文件夹保存在program files文件夹中。
但是,我无法在 cmd 中 运行 节点或 npm 命令,除非我所在的路径是 Program Files 或 Program Files。如何在任何地方使用这些命令?
提前致谢!
嗯,您需要将该目录添加到您的 Path 环境变量中。
通常,nodejs 在安装期间会为您完成此操作,但如果您忘记 select 该选项,您可以随时手动添加它:
- 在 Windows 中打开“开始”菜单,键入 "env" 和 select "Edit the system environment variables",您最终会进入系统属性对话框的 "Advanced" 选项卡.在此选项卡上,您可以看到四个按钮,最后一个按钮显示 "Environment variables"
- 单击该按钮打开环境变量对话框,您将在其中看到两个面板,上面是当前用户的变量,下面是系统范围的变量。
- 在两个面板中,您都可以找到一个名为 "Path" 的变量。 Select 您要编辑的那个(用户范围或系统范围),然后单击 "Edit"。
- 在“编辑”对话框中,您会看到 "Path" 变量中当前的 Windows 个路径列表。您需要单击 "New",这会创建一个新条目,然后单击 "Find..." 打开 window,让您 select 系统上的一个文件夹。在那里,找到 select 您安装 nodejs 的文件夹,即包含 "node.exe" 可执行文件以及 "npm" 和 "npx" 脚本的文件夹。
- 保存所有内容,启动 CMD 或 PowerShell,然后输入
node --version
进行测试
或者,只需重新安装节点,在安装过程中,注意复选框显示 "Add installation folder to %PATH%" 之类的内容。
如果你使用Windows.
来自 www.howtogeek.com:
The Windows System PATH tells your PC where it can find specific directories that contain executable files. ipconfig.exe, for example, is found in the C:\Windows\System32 directory, which is a part of the system PATH by default. When you type ipconfig into a Command Prompt, Windows doesn’t need to know where that EXE is–it’ll check all the folders in its PATH until it finds the right one.
所以我们要在path环境变量中加上nodejs安装文件夹的路径(里面有node.exe和npm.exe两个文件)
所以windows键盘上的按钮和搜索编辑系统环境变量。
打开它然后在系统变量设置中搜索路径
点击编辑然后插入新行:
C:\程序Files\nodejs\
或者你安装node的地方。
(如果你进入这个目录,你会看到 npm.cmd 和 node.exe 文件)。
重启。
现在在 cmd 上随处尝试 npm 或节点命令。
所以,我在电脑上安装了node.js,并将nodejs文件夹保存在program files文件夹中。
但是,我无法在 cmd 中 运行 节点或 npm 命令,除非我所在的路径是 Program Files 或 Program Files。如何在任何地方使用这些命令?
提前致谢!
嗯,您需要将该目录添加到您的 Path 环境变量中。 通常,nodejs 在安装期间会为您完成此操作,但如果您忘记 select 该选项,您可以随时手动添加它:
- 在 Windows 中打开“开始”菜单,键入 "env" 和 select "Edit the system environment variables",您最终会进入系统属性对话框的 "Advanced" 选项卡.在此选项卡上,您可以看到四个按钮,最后一个按钮显示 "Environment variables"
- 单击该按钮打开环境变量对话框,您将在其中看到两个面板,上面是当前用户的变量,下面是系统范围的变量。
- 在两个面板中,您都可以找到一个名为 "Path" 的变量。 Select 您要编辑的那个(用户范围或系统范围),然后单击 "Edit"。
- 在“编辑”对话框中,您会看到 "Path" 变量中当前的 Windows 个路径列表。您需要单击 "New",这会创建一个新条目,然后单击 "Find..." 打开 window,让您 select 系统上的一个文件夹。在那里,找到 select 您安装 nodejs 的文件夹,即包含 "node.exe" 可执行文件以及 "npm" 和 "npx" 脚本的文件夹。
- 保存所有内容,启动 CMD 或 PowerShell,然后输入
node --version
进行测试
或者,只需重新安装节点,在安装过程中,注意复选框显示 "Add installation folder to %PATH%" 之类的内容。
如果你使用Windows.
来自 www.howtogeek.com:
The Windows System PATH tells your PC where it can find specific directories that contain executable files. ipconfig.exe, for example, is found in the C:\Windows\System32 directory, which is a part of the system PATH by default. When you type ipconfig into a Command Prompt, Windows doesn’t need to know where that EXE is–it’ll check all the folders in its PATH until it finds the right one.
所以我们要在path环境变量中加上nodejs安装文件夹的路径(里面有node.exe和npm.exe两个文件)
所以windows键盘上的按钮和搜索编辑系统环境变量。
打开它然后在系统变量设置中搜索路径
点击编辑然后插入新行:
C:\程序Files\nodejs\
或者你安装node的地方。
(如果你进入这个目录,你会看到 npm.cmd 和 node.exe 文件)。
重启。
现在在 cmd 上随处尝试 npm 或节点命令。