nvm node 版本管理器安装使用

小鱼
2025-08-09 12:46:31
nvmnodejs

nvm 能在同一机器上快速安装和运行不同版本的nodejs,是nodejs的版本管理器

安装

windows

下载地址

https://www.nvmnode.com/guide/download.html

进去推荐使用非github链接下载,国内支持友好

linux

官网地址

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash

国内加速地址

curl -o- https://gitee.com/mirrors/nvm/raw/master/install.sh | bash
curl -o- https://hub.fastgit.xyz/nvm-sh/nvm/raw/master/install.sh | bash

镜像配置

nvm安装nodejs时使用的是官方安装地址,国内访问过于慢,甚至会报错,因此配置为国内镜像即可

windows

修改安装目录下 settings.txt 文件添加以下内容:

node_mirror: https://npmmirror.com/mirrors/node/
npm_mirror: https://npmmirror.com/mirrors/npm/

linux

~/.bashrc~/.zshrc 中添加:

export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

加载nvm生效

source ~/.bashrc 或者 source ~/.zshrc

验证NVM

nvm --version  # 查看安装版本
nvm list available # 查看可安装nojs版本
nvm install [版本号]  # 安装指定版本nodejs,测试下载速度
nvm ls # 查看已安装的nodejs版本
nvm use [版本号] # 切换使用指定nodejs版本
Copyright © 2025 aipanzhou.com All Rights Reserved.
备案号:黔ICP备2023000741号-1
贵公网安备 52022202000096号