nvm:NodeJs版本管理工具下载安装与使用教程
nvm是什么
nvm是一个node的版本管理工具,可以简单操作node版本的切换、安装、查看。。。等等,与npm不同的是,npm是依赖包的管理工具。
nvm特点
node:是一个基于 Chrome V8 引擎的 JS 运行环境。
npm:是 node.js 默认的包管理系统(用 JavaScript 编写的),在安装的 node 的时候,npm 也会跟着一起安装,管理 node 中的第三方插件。
nvm:node 版本管理器,也就是说:一个 nvm 可以管理多个 node 版本(包含 npm 与 npx),可以方便快捷的 安装、切换 不同版本的 node。
如何下载
官方网址:https://www.nvmnode.com
windows下载exe安装
Linux/MacOS/WSL
Linux 和 MacOS 使用的是原始的 nvm-sh/nvm 版本。
安装方法
您可以通过以下命令之一安装 NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash或者:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash中国大陆加速方法:
curl -o- https://hub.gitmirror.com/raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash或者:
wget -qO- https://hub.gitmirror.com/raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/instalnvm常用命令
nvm list available:查看可在线安装的NodeJS版本
nvm ls:列出所有已经在NVM中安装的NodeJS版本。
nvm current:显示当前正在使用的Node版本。
nvm install xx.xx.xx:在NVM中在线安装指定版本的NodeJS,xx.xx.xx为指定的版本号。
nvm uninstall xx.xx.xx:在NVM中卸载指定版本的NodeJS,xx.xx.xx为指定的版本号。
nvm use xx.xx.xx:切换NodeJS版本,xx.xx.xx为指定的版本号。
nvm version:显示当前所使用的NVM的版本号。
其它命令,如nvm arch、nvm on、nvm off、nvm proxy、nvm node_mirror、nvm npm_mirror、nvm root等,
npm在国内存在下载速度比较慢的问题。为解决这个问题,需要切换npm下载源为国内的镜像源
npm国内下载镜像汇总:
npm官方原始镜像: https://registry.npmjs.org/
淘宝npm镜像:http://registry.npmmirror.com
阿里云npm镜像: https://npm.aliyun.com
腾讯云npm镜像: https://mirrors.cloud.tencent.com/npm/
华为云npm镜像: https://mirrors.huaweicloud.com/repository/npm/
网易npm镜像: https://mirrors.163.com/npm/
中科大开源镜像站: http://mirrors.ustc.edu.cn/
清华大学开源镜像站: https://mirrors.tuna.tsinghua.edu.cn/
查看当前使用的npm镜像源,使用命令:
npm config get registry
切换npm镜像源,使用命令:
npm config set registry http://mirrors.cloud.tencent.com/npm/
切换为国内的镜像源之后,确认是否切换成功,查看当前使用的npm镜像,命令
npm config get registry
以上命令运行效果如图:
使用nrm管理镜像源
nrm是一个npm源管理工具,可以使用nrm切换不同的镜像源
先恢复官方的镜像源,使用命令
npm config set registry https://registry.npmjs.org/
安装nrm,命令:
npm install -g nrm
使用nrm查看有哪些npm镜像源, 命令:
nrm ls
运行命令,会得到类似以下结果的输出
npm ---- https://registry.npmjs.org/
yarn ---- https://registry.yarnpkg.com/
tencent - https://mirrors.cloud.tencent.com/npm/
huawei -- https://repo.huaweicloud.com/repository/npm/
使用nrm切换npm镜像源,需要用到nrm ls命令中得到的结果,命令如下:
nrm npmMirror
恢复官方源,运行命令:
npm config set registry https://registry.npmjs.org/
