node.js 修复 Windows 8 和 10 中的 npm 路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27864040/
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-02 18:17:55  来源:igfitidea点击:

Fixing npm path in Windows 8 and 10

node.jsnpm

提问by Bachalo

Have done a lot of googling, tried reinstalling node.js using the official installer, but my npm pathing still doesn't work.

已经做了很多谷歌搜索,尝试使用官方安装程序重新安装 node.js,但我的 npm 路径仍然不起作用。

This doesn't work

这不起作用

npm install foo

I get an error message saying missing module npm-cli.js

我收到一条错误消息,指出缺少模块 npm-cli.js

2 hours of googling later I discovered a workaround
Instead of simply 'npm' I type

谷歌搜索 2 小时后,我发现了一个解决方法,
而不是简单地输入“ npm

node C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js

But how can I correct my nodejs install so I can simply type 'npm' ?

但是如何更正我的 nodejs 安装,以便我可以简单地输入 'npm' ?

回答by wjohnsto

You need to Add C:\Program Files\nodejsto your PATH environment variable. To do this follow these steps:

您需要添加C:\Program Files\nodejs到 PATH 环境变量。为此,请执行以下步骤:

  1. Use the global Search Charm to search "Environment Variables"
  2. Click "Edit system environment variables"
  3. Click "Environment Variables" in the dialog.
  4. In the "System Variables" box, search for Path and edit it to include C:\Program Files\nodejs. Make sure it is separated from any other paths by a ;.
  1. 使用全局 Search Charm 搜索“环境变量”
  2. 点击“编辑系统环境变量”
  3. 单击对话框中的“环境变量”。
  4. 在“系统变量”框中,搜索 Path 并将其编辑为包含C:\Program Files\nodejs. 确保它与任何其他路径以;.

You will have to restart any currently-opened command prompts before it will take effect.

您必须重新启动任何当前打开的命令提示符才能生效。

回答by Yar

get the path from npm:

从 npm 获取路径:

npm config get prefix

npm config get prefix

and just as a future reference, this is the path I added in Windows 10:

作为将来的参考,这是我在 Windows 10 中添加的路径:

C:\Users\{yourName}\AppData\Roaming\npm

C:\Users\{yourName}\AppData\Roaming\npm





Update:

更新:

If you want to add it for all users just add the following path [by @glenn-lawrence from the comments]:

如果您想为所有用户添加它,只需添加以下路径 [来自评论的@glenn-lawrence]:

%AppData%\npm

%AppData%\npm

回答by Martez C

I have used the cmdlet and navigate to the path you want to switch your npm files to. Type in npm root -gto see what the current path your npm is installed to. Next use npm config set prefixand your npm path will be changed to whatever directory you are currently on.

我已经使用了 cmdlet 并导航到您要将 npm 文件切换到的路径。输入npm root -g以查看您的 npm 安装到的当前路径。接下来使用npm config set prefix,您的 npm 路径将更改为您当前所在的任何目录。

回答by Dennington-bear

Go to control panel -> System -> Advanced System Settings then environment variables.

转到控制面板 -> 系统 -> 高级系统设置,然后是环境变量。

From here find the path variable, Go to the end of the line and paste "C:\Program Files\nodejs\node_modules\npm\bin" (change the path to the directory to where ever you installed it e.g. if you specifically installed it anywhere change it)

从这里找到路径变量,转到行尾并粘贴“C:\Program Files\nodejs\node_modules\npm\bin”(将目录的路径更改为安装它的位置,例如,如果您专门安装它任何地方改变它)

回答by Dennington-bear

Try this one dude if you're using windows:

1.) Search environment variables at your start menu's search box.
2.) Click it then go to Environment Variables...
3.) Click PATH, click Edit
4.) Click Newand try to copy and paste this: C:\Program Files\nodejs\node_modules\npm\bin

如果您使用的是 Windows,请试试这个老兄:

1.) 在开始菜单的搜索框中搜索环境变量。
2.) 单击它然后转到Environment Variables...
3.) 单击PATH,单击Edit
4.) 单击New并尝试复制并粘贴:C:\Program Files\nodejs\node_modules\npm\bin

If you got an error. Do the number 4.) Click New, then browse the binfolder

如果你有错误。执行数字 4。)单击新建,然后浏览bin文件夹

  • 您也可以访问此链接了解更多信息。

回答by Altin

Installed Node Version Manager (NVM) for Windows: https://github.com/coreybutler/nvm-windows

已安装的 Windows 节点版本管理器 (NVM):https: //github.com/coreybutler/nvm-windows

I'm using Windows 10 - 64 bit so I run... Commands:

我使用的是 Windows 10 - 64 位,所以我运行...命令:

  • nvm arch 64(to make default the 64 bit executable)
  • nvm list(to list all available node versions)
  • nvm install 8.0.0(to download node version 8.0.0 - you can pick any)
  • nvm use 8.0.0(to use that specific version)
  • nvm arch 64(使默认的 64 位可执行文件)
  • nvm list(列出所有可用的节点版本)
  • nvm install 8.0.0(要下载节点版本 8.0.0 - 您可以选择任何版本)
  • nvm use 8.0.0(使用该特定版本)

In my case I had to just switch to version 8.5.0and then switch back again to 8.0.0and it was fixed. Apparently NVM sets the PATH variables whenever you do that switch.

就我而言,我只需要切换到8.5.0版,然后再切换回8.0.0 版就可以了。显然,每当您进行切换时,NVM 都会设置 PATH 变量。

回答by marty

This worked for me: 1. npm root -g(to see the current npm is installed) 2. npm config set prefix(to change the path)

这对我有用: 1. npm root -g(查看当前安装的npm) 2. npm config set prefix(更改路径)

回答by Md Wahid

You can follow the following steps:

您可以按照以下步骤操作:

  • Search environment variablesfrom start menu's search box.
  • Click it then go to Environment Variables
  • Click PATH
  • click Edit
  • Click Newand try to copyand pasteyour path for 'bin' folder [find where you installed the node] for example according to my machine 'C:\Program Files\nodejs\node_modules\npm\bin'
  • 从开始菜单的搜索框中搜索环境变量
  • 单击它然后转到环境变量
  • 单击路径
  • 单击编辑
  • 单击“新建”并尝试复制粘贴bin”文件夹的路径[找到您安装节点的位置],例如根据我的机器“ C:\Program Files\nodejs\node_modules\npm\bin

If you got any error. try the another step:

如果你有任何错误。尝试另一个步骤:

  • Click New, then browse for the 'bin' folder
  • 单击“新建”,然后浏览“ bin”文件夹

回答by willey

Edit the System environment variables, and enter following path:

编辑系统环境变量,输入以下路径:

C:\Program Files\nodejs\node.exe;

C:\Program Files\nodejs\node.exe;

C:\Users\{yourName}\AppData\Roaming\npm

C:\Users\{yourName}\AppData\Roaming\npm

回答by Premium Ayodele

If after installing your npm successfully, and you want to install VueJS then this is what you should do

如果在成功安装 npm 后,你想安装 VueJS 那么这就是你应该做的

after running the following command (as Admin)

运行以下命令后(以管理员身份)

npm install --global vue-cli

npm install --global vue-cli

It will place the vue.cmd in the following directory C:\Users\YourUserName\AppData\Roaming\npm

它将把 vue.cmd 放在以下目录中 C:\Users\YourUserName\AppData\Roaming\npm

you will see this in your directory.

你会在你的目录中看到这个。

Now to use vue as a command in cmd. Open the cmd as admin and run the following command.

现在在 cmd 中使用 vue 作为命令。以管理员身份打开 cmd 并运行以下命令。

setx /M path "%path%;%appdata%\npm"

setx /M path "%path%;%appdata%\npm"

Now restart the cmd and run the vue again. It should work just fine, and then you can begin to develop with VueJS.

现在重新启动cmd并再次运行vue。它应该可以正常工作,然后您就可以开始使用 VueJS 进行开发了。

I hope this helps.

我希望这有帮助。