Mac nvm的简单使用

252 阅读1分钟

Mac安装nvm

下载

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

配置

  • 如果使用的是zsh,在~/.zshrc中添加以下配置,然后执行source ~/.zshrc
  • 如果使用的是bash,在~/.bash_profile中添加以下配置,然后执行source ~./bash_profile
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

使用

安装node

// 安装指定版本
nvm install v8.0.0
// 安装最后一个稳定版本
nvm install --lts

查看所有的node版本

nvm ls

指定使用的node版本

nvm use v8.0.0

查看当前使用的node版本

nvm current

卸载node

nvm uninstall v8.0.0

不同目录使用不同的node版本

  1. 在目标目录下新建文件.nvmrc
  2. 添加要使用的node版本echo “8.0.0” > .nvmrc
  3. 使用nvm use激活