NVM 版本管理工具
nvm 是 Node Version Manager 的缩写,是一个用于管理多个 node 版本的 shell 脚本工具。在项目开发中,我们可能需要用不同版本的 Node.js 开发和测试,nvm 就可以帮助我们设置默认 node 版本,在不同开发环境中切换不同版本。
GitHub 地址:https://github.com/nvm-sh/nvm
安装 nvm
nvm 项目提供了一个 install.sh 脚本帮助用户快速安装,可以使用 cURL 或 Wget 等工具下载。
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
运行上面命令中的任意一条,就会下载并运行 v0.39.1 版本的 nvm,默认安装位置为 ~/.nvm
,并会在一些配置文件中添加如下代码片段,例如 ~/.bash_profile
、~/.zshrc
、~/.profile
或 ~/.bashrc
。
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