Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在 Windows 系统下安装 Node.js 时出现权限问题时的解决方案 #33

Open
lmk123 opened this issue Jan 19, 2016 · 0 comments

Comments

@lmk123
Copy link
Owner

lmk123 commented Jan 19, 2016

在 Windows 下安装 Node.js 时,若启用了 Add to PATH 选项(默认启用),但当前账号又没有足够的权限读写环境变量时,在安装过程中会弹出警告,安装结束后运行命令行 node -vnpm -v 都会提示“命令不存在”。

这种情况下,我需要手动将 node 与 npm 这两个路径添加到环境变量中。

首先需要知道安装 Node.js 时的安装路径。默认情况下,Node.js 会被安装到 C:\Program Files\nodejs

依次打开“控制面板”->“系统”->“高级系统设置”,切换到“高级”选项卡,点击下方的“环境变量”按钮,在用户变量里或者系统变量里找到名为 PATH 的变量,然后单击它并点击下方的“编辑”,在值里面追加上面说的 Node.js 的安装路径,并用分号(;)隔开,例如 ;C:\Program Files\nodejs

点击“确定”后不要关闭“高级系统设置”,现在只添加了 node 命令,后面还需要添加 npm 命令。

打开一个命令提示符,输入 node -vnpm -v,现在就能显示安装的 Node.js 的版本号了。

然后安装最新版的 npm:

npm i npm -g

安装完成后会显示 npm 的安装路径,一般情况下是 C:\Users\你的用户名\AppData\Roaming\npm。将这个路径以同样的方法追加到上面说的 PATH 环境变量里。

然后再安装全局模块(特别是附带命令行的模块)时,就能正确找到命令了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant