macOS 安装 nvm 和 Node.js

1. 安装 nvm

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

2. 加载 nvm(立即生效)

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

或重启终端后执行:

source ~/.zshrc

3. 配置国内镜像(加速下载)

export NVM_NODEJS_ORG_MIRROR=https://registry.npmmirror.com/-/binary/node

永久配置(添加到 ~/.zshrc):

echo 'export NVM_NODEJS_ORG_MIRROR=https://registry.npmmirror.com/-/binary/node' >> ~/.zshrc

4. 安装 Node.js

# 查看可用版本
nvm ls-remote | grep "v24"

# 安装 Node.js 24
nvm install 24

# 设置默认版本
nvm alias default 24

# 验证
node -v
npm -v

常用命令

nvm ls                  # 查看已安装版本
nvm use 24              # 切换版本
nvm uninstall 20        # 卸载版本
最后修改:2026 年 03 月 14 日
如果觉得我的文章对你有用,请随意赞赏