共计 2438 个字符,预计需要花费 7 分钟才能阅读完成。
提醒:本文最后更新于2025-07-07 14:41,文中所关联的信息可能已发生改变,请知悉!
本文提到的 nvm
指的是 Node.js version management
,用于 Node.js 多版本切换管理的工具。开源社区里有基于不同语言和不同系统的实现,但基本功能与用法都类似。
- coreybutler/nvm-windows – windows 上使用最多的选择
- nvm-sh/nvm – Mac / Linux 上使用最多的选择
- jasongin/nvs – 支持所有主流系统平台的 Node.js 管理器
- Schniz/fnm – 使用
rust
开发的支持多平台的 Node.js 版本管理器
1. 下载与安装 nvm
1.1 windows: 下载 nvm windows 安装包
从 nvm-windows 在 github 的 releases 页面下载 setup 版本。
地址: https://github.com/coreybutler/nvm-windows/releases
下载完成后解压,执行 exe 程序进行安装。安装完成后打开 cmd 命令行,输入 nvm v
,看到版本号输出,则说明安装成功。
1.2 Mac 下安装 nvm
这里介绍的是 nvm-sh/nvm
的安装示例。
使用 brew:
brew install nvm | |
nvm --help |
从 nvm 仓库的 sh 命令安装:
curl -o- https://ghproxy.com/raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash | |
# 或者使用 wget: | |
wget -qO- https://ghproxy.com/raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash |
2. nvm 使用
Usage: | |
nvm arch : Show if node is running in 32 or 64 bit mode. | |
nvm install <version> [arch] : The version can be a node.js version or "latest" for the latest stable version. | |
Optionally specify whether to install the 32 or 64 bit version (defaults to system arch). | |
Set [arch] to "all" to install 32 AND 64 bit versions. | |
Add --insecure to the end of this command to bypass SSL validation of the remote download server. | |
nvm list [available] : List the node.js installations. Type "available" at the end to see what can be installed. Aliased as ls. | |
nvm on : Enable node.js version management. | |
nvm off : Disable node.js version management. | |
nvm proxy [url] : Set a proxy to use for downloads. Leave [url] blank to see the current proxy. | |
Set [url] to "none" to remove the proxy. | |
nvm node_mirror [url] : Set the node mirror. Defaults to https://nodejs.org/dist/. Leave [url] blank to use default url. | |
nvm npm_mirror [url] : Set the npm mirror. Defaults to https://github.com/npm/cli/archive/. Leave [url] blank to default url. | |
nvm uninstall <version> : The version must be a specific version. | |
nvm use [version] [arch] : Switch to use the specified version. Optionally specify 32/64bit architecture. | |
nvm use <arch> will continue using the selected version, but switch to 32/64 bit mode. | |
nvm root [path] : Set the directory where nvm should store different versions of node.js. | |
If <path> is not set, the current root will be displayed. | |
nvm version : Displays the current running version of nvm for Windows. Aliased as v. |
使用示例:
# 查看本地已经安装的 node 版本 | |
nvm list | |
# 安装指定版本的 node | |
nvm install v8.9.4 | |
# 切换 node 版本 | |
nvm use v8.9.4 | |
# 设置默认版本node | |
nvm alias default v8.9.4 | |
# 查看当前系统架构下可下载的 node 版本 | |
nvm ls available |
3. nvm 设置国内淘宝镜像
windows 下:
nvm node_mirror https://npmmirror.com/mirrors/node/ | |
nvm npm_mirror https://npmmirror.com/mirrors/npm/ |
Mac 下:
vim ~/.bash_profile | |
// 加入以下两条配置文件 | |
export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node | |
export NVM_IOJS_ORG_MIRROR=https://npmmirror.com/mirrors/iojs | |
// 重启配置文件 | |
source ~/.bashrc |
扩展参考
- https://github.com/nvm-sh/nvm#installing-and-updating
相关文章:












正文完