环境 - fnm
卸载所有已有的Node安装
nvm-windows
下载
https://github.com/coreybutler/nvm-windows/releases
安装完确认 打开CMD,输入命令 nvm ,安装成功则如下显示,可以看到里面列出了各种命令
npm config set registry https://registry.npmmirror.com修改settings.txt 在你安装的nvm目录下找到settings.txt文件,打开settings.txt文件后,加上下面两行代码: node_mirror: https://npm.taobao.org/mirrors/node/ npm_mirror: https://npm.taobao.org/mirrors/npm/ 目的是将npm镜像改为淘宝的镜像,可以提高下载速度
问题
终端(管理员)可以使用nvm命令,普通终端无法使用nvm命令
原因:NVM_HOME所在的目录,当前用户可能无权限访问。重新安装到当前用户路径下
bash
echo $Env:NVM_HOME运行npm命令报错
bash
$ npm -v
npm : 无法加载文件 C:\nvm4w\nodejs\npm.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fw
link/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ npm -v
+ ~~~
+ CategoryInfo : SecurityError: (:) [],PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess解决方案
1.先以管理员身份打开终端
2.输入命令来更改执行策略为 RemoteSigned 并设置为作用于当前用户(这样后续该用户使用 PowerShell 时都会应用这个策略)
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned配置镜像源
windows
powershell
# 设置fnm镜像源
$env:FNM_NODE_DIST_MIRROR="https://mirrors4.tuna.tsinghua.edu.cn/nodejs-release/"
# 然后正常使用fnm安装版本,例如
fnm install 24linux
bash
# 设置fnm镜像源(临时有效)
export FNM_NODE_DIST_MIRROR="https://mirrors4.tuna.tsinghua.edu.cn/nodejs-release/"
# 然后正常使用fnm安装版本,例如
fnm install 24