# Mac 下安装 nvm

URL: https://caijiao.org/nvm/install/mac
Source: docs/nvm/install/mac.md
Description: 在 Mac 下安装 NVM，只需运行 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash，然后重新加载 shell 配置文件并验证安装。

在 Mac 下安装 NVM（Node Version Manager）非常简单，以下是具体步骤：

## 1. 使用安装脚本安装 NVM

打开终端，然后运行以下命令以下载并运行 NVM 的安装脚本：

```bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
```

或者，如果你使用 `wget`，可以运行：

```bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
```

## 2. 重新加载 Shell 配置文件

安装脚本会将 NVM 的路径添加到你的 shell 配置文件中（如 `.bash_profile`、`.zshrc` 或 `.profile`）。你需要重新加载这个文件使 NVM 生效。

对于 `bash` 用户：

```bash
source ~/.bash_profile
```

对于 `zsh` 用户：

```bash
source ~/.zshrc
```

## 3. 验证安装

你可以运行以下命令来验证 NVM 是否成功安装：

```bash
nvm --version
```

如果安装成功，该命令会输出 NVM 的版本号。

## 4. 使用 NVM 安装和管理 Node.js

现在你已经安装了 NVM，可以使用它来安装和管理不同版本的 Node.js。

### 安装最新版本的 Node.js

```bash
nvm install node
```

### 安装特定版本的 Node.js

```bash
nvm install 14.17.0
```

### 切换到特定版本的 Node.js

```bash
nvm use 14.17.0
```

### 列出已安装的 Node.js 版本

```bash
nvm ls
```

### 列出所有可安装的 Node.js 版本

```bash
nvm ls-remote
```

## 5. 设置默认 Node.js 版本

你可以设置一个默认的 Node.js 版本，当打开新的终端会话时会自动使用该版本：

```bash
nvm alias default 14.17.0
```

通过以上步骤，你就可以在 Mac 下安装并使用 NVM 来管理 Node.js 版本了。
