node.js npm global install 不会将软件包添加到 Windows 8.1 上的 PATH
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23860262/
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
npm global install does not add packages to PATH on Windows 8.1
提问by Zain Rizvi
When I run npm install -g <package>it installs the packages in my user/AppData/Roaming/npm/npm_modules/ folder. This sub-folder is not in my PATH so if I try to run the package without explicitly calling the entire path the call fails with a '<package>' is not recognized as an internal or external command, operable program or batch file.
当我运行时,npm install -g <package>它会在我的 user/AppData/Roaming/npm/npm_modules/ 文件夹中安装软件包。这个子文件夹不在我的 PATH 中,所以如果我尝试运行包而不显式调用整个路径,调用失败并显示'<package>' is not recognized as an internal or external command, operable program or batch file.
What can I do to fix this?
我能做些什么来解决这个问题?
Thanks
谢谢
回答by luochen1990
I'm using win8.1 and I found that the nodejs installer didn't add the path to global node modules to the system PATH. Just add %AppData%\npm;to the user variable(since %AppData% dir is depending on user) PATHto fix it.
我使用的是 win8.1,我发现 nodejs 安装程序没有将全局节点模块的路径添加到系统路径中。只需添加%AppData%\npm;到用户变量(因为 %AppData% 目录取决于用户)PATH来修复它。
You will need to log out then log back in for the change to your PATH variable to take effect.
您需要注销然后重新登录以使对 PATH 变量的更改生效。
SET PATH=%AppData%\npm;%PATH%
回答by user3662697
You have to run this line SET PATH=pathtonodejs;%PATH%(where pathtonodejsis where you installed nodejs) once the installation for nodejs is complete and it should work.
一旦 nodejs 安装完成,你必须运行这一行SET PATH=pathtonodejs;%PATH%(pathtonodejs你安装 nodejs 的位置)并且它应该可以工作。
回答by Zain Rizvi
It turned the problem was a change in behavior of the module I was using.
结果问题是我使用的模块的行为发生了变化。
I'd been following old tutorials for using Express.js. The old tutorials assumed Express would be in my path after installing it globally, but as of Express v4.0 there's a separate Express module you have to install in order to get it in your path
我一直在学习使用 Express.js 的旧教程。旧教程假设 Express 在全局安装后会在我的路径中,但是从 Express v4.0 开始,您必须安装一个单独的 Express 模块才能将其放入您的路径中

