运行windows 7 Professional 32bit。
我试着在normal或admin下运行npm install -g angular-cli。
我还尝试将它添加到PATH: (C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng)下的环境变量中,也没有成功。
我做错了什么?
运行windows 7 Professional 32bit。
我试着在normal或admin下运行npm install -g angular-cli。
我还尝试将它添加到PATH: (C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng)下的环境变量中,也没有成功。
我做错了什么?
当前回答
在尝试更新Windows 7 (x64)上的PATH变量之前,运行CMD控制台AS ADMINISTRATOR和ng命令对我有用,这也适用于VISUAL STUDIO CODE控制台。
它为我工作在CMD控制台/ VS CODE
其他回答
由于这个问题在一年后仍然被反复问到,我将在这里发布我的答案。
提示(仅在Windows上)是正确地安排path变量中的条目。
正如NPM wiki告诉我们的:
因为安装程序将C:\Program Files (x86)\nodejs放在你的PATH上的C:\Users\ AppData\Roaming\npm之前,所以它总是使用node安装的npm版本,而不是你使用npm -g install npm@<version>安装的npm版本。
所以你的路径变量看起来像这样:
…;C: \ < path-to-node-installation >; % appdata % \ npm;…
现在你有两种可能:
交换这两个元素,它看起来就像
…;%appdata%\npm;C:\<path-to-node-installation>;…
这将加载与npm一起安装的npm版本(而不是与node一起安装)和已安装的Angular CLI版本。
如果你(无论出于什么原因)喜欢使用npm版本和node绑定,将直接路径添加到你的全局Angualr CLI版本中。C:\Users\<username>\AppData\Roaming\npm\node_modules\@angular\cli;C:\<path-to-node-installation>;% AppData %\npm; 或者……;% appdata % \ npm \ node_modules \ @angular \ cli; C: \ < path-to-node-installation >; % appdata % \ npm;… 简写形式。
这对我来说很管用。
我有同样的问题,Visual Studio代码不能在它的内置终端中运行任何ng命令。
我添加了%AppData%\npm到Windows 10的路径中,并且不需要重新启动,只是关闭和重新打开VS Code,它看不到它。
我必须将npm路径添加到user path环境变量中。你可以以管理员身份运行以下PowerShell脚本:
$path = npm config get prefix
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if (($userPath -split ';') -notcontains $path)
{
[Environment]::SetEnvironmentVariable("PATH", ('{0};{1}' -f $userPath, $path), "User")
}
您可以这样办理登机手续。我也有同样的问题。首先,在环境变量中检查用户PATH。它必须指向%USERPROFILE%\AppData\Roaming\npm\node_modules\@angular\cli\
使用node.js命令提示符代替命令提示符。在安装的程序菜单中运行node.js命令提示符。点击开始,搜索node.js命令提示符。运行它,然后输入ng -v回车。它会起作用的。如果有帮助,请告诉我。
对我来说,它适用于:
npm run ng <command>