nvm - Node 版本管理工具
info
Node 版本管理工具,可以在本地保存并安装多个 Node 版本,解决新老前端项目的版本依赖冲突。
nvm
allows you to quickly install and use different versions of node
via the command line.
Install
use the following cURL
or Wget
command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
配置文件
将下面的配置代码片段复制进配置文件中 (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).
我这里是 vim .zprofile
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
保存后 source .zprofile
验证生效
# 查看版本号
nvm -v
常用命令
# 安装最新的稳定版本node
nvm install stable
# 安装指定版本
nvm install <verison>
# 查看本地所有安装的版本
nvm ls
# 切换使用指定的版本 node
nvm use <version>
# 删除已安装的指定版本
nvm uninstall <version>
Debug
如果使用过程中,又出现 nvm command not found
重新执行如下命令:
source ~/.zprofile