# nvm-install-cn **Repository Path**: iamzhihuix/nvm-install-cn ## Basic Information - **Project Name**: nvm-install-cn - **Description**: nvm国内版安装脚本 - **Primary Language**: Shell - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2025-10-28 - **Last Updated**: 2025-11-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 🟢 NVM CN Installer |中国大陆友好的 Node.js 安装脚本 > 💡 一键安装 **nvm + Node.js + 国内 npm 镜像** > 零 `sudo`、全自动、适配 macOS & Linux、适合初学者与开发者。 ---

platform language license mirror node-lts

--- ## 👤 作者信息 - **姓名**:志辉 - **联系**: --- ## 🚀 一键安装(推荐) ### 🌍 GitHub(国际) ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/iamzhihuix/nvm-install-cn/main/install.sh)" ``` ### 🇨🇳 Gitee(国内加速,推荐) ```bash /bin/bash -c "$(curl -fsSL https://gitee.com/iamzhihuix/nvm-install-cn/raw/main/install.sh)" ``` > 🧩 默认行为: > - 从 **Gitee 镜像** 安装 `nvm` > - 自动安装 **最新 LTS Node.js** > - 写入 `~/.zshrc` 或 `~/.bashrc` 环境变量 > - 配置全部 **npm 国内镜像源**(含 Electron、Puppeteer、Sass) > - 启用 corepack(pnpm / yarn 支持) > - 无需 `sudo`、即装即用 ✅ --- ## 🌈 功能概览 | 功能项 | 描述 | |--------|------| | ⚙️ **自动检测 Shell** | 自动识别 zsh / bash 并更新配置文件 | | 📦 **Node LTS 自动安装** | 一键获取最新长期支持版 Node | | 🌐 **国内镜像全覆盖** | npm、Electron、Puppeteer、Sass 全部走 npmmirror | | 🧱 **无 sudo 权限要求** | 全部安装在用户目录下 | | 🔁 **幂等执行** | 重复运行不会重复插入环境变量 | | 💡 **即装即用体验** | 终端重启后即生效 | --- ## 🧰 使用参数(可选) | 参数 | 作用 | |------|------| | `--with-node` | (默认)安装最新 LTS Node | | `--without-node` | 只安装 nvm,不安装 Node | | `--rc <文件>` | 指定配置文件路径,如 `--rc ~/.bash_profile` | 示例(以 Gitee 为例): ```bash # 只安装 nvm,不安装 Node bash -c "$(curl -fsSL https://gitee.com/iamzhihuix/nvm-install-cn/raw/main/install.sh)" -- --without-node # 指定配置文件 bash -c "$(curl -fsSL https://gitee.com/iamzhihuix/nvm-install-cn/raw/main/install.sh)" -- --rc ~/.bash_profile # GitHub 方式(可替换为上述任一地址) bash -c "$(curl -fsSL https://raw.githubusercontent.com/iamzhihuix/nvm-install-cn/main/install.sh)" -- --without-node ``` --- ## ⚡ 安装完成后验证 ```bash nvm --version node -v npm -v npm config get registry ``` 输出应类似: ``` nvm: 0.39.7 node: v22.11.0 npm: 10.8.3 registry: https://registry.npmmirror.com ``` --- ## 🇨🇳 国内镜像加速策略 | 类型 | 配置地址 | 说明 | |------|-----------|------| | Node.js | `https://npmmirror.com/mirrors/node/` | nvm 安装 Node 镜像 | | npm | `https://registry.npmmirror.com` | 包下载加速 | | Electron | `https://npmmirror.com/mirrors/electron/` | Electron 二进制 | | Puppeteer | `https://npmmirror.com/mirrors` | Chromium 镜像 | | Node-Sass | `https://npmmirror.com/mirrors/node-sass` | 二进制模块镜像 | > ✨ 所有这些镜像都会在安装脚本中自动写入配置,无需再次手动设置。 --- ## 🔍 路径验证 ```bash which node which npm npm root -g ``` 输出应全部位于: ``` /Users/<你>/.nvm/versions/node/<版本号>/ ``` ✅ 表示成功避开 `/usr/local`,再也不用 `sudo`! --- ## 🧠 常见问题 **Q1:执行完脚本后 `nvm` 命令未找到?** 👉 脚本已自动执行 `source`,若仍未生效,请重新打开一个终端,或执行: ```bash source ~/.zshrc # 或 source ~/.bashrc ``` --- **Q2:如何切换 Node 版本?** ```bash nvm ls-remote --lts # 查看所有 LTS 版本 nvm install v20.14.0 # 安装指定版本 nvm use v20.14.0 # 切换版本 nvm alias default v20.14.0 ``` --- **Q3:如何卸载 nvm?** ### 🌍 GitHub(国际) ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/iamzhihuix/nvm-install-cn/main/uninstall.sh)" ``` ### 🇨🇳 Gitee(国内加速,推荐) ```bash /bin/bash -c "$(curl -fsSL https://gitee.com/iamzhihuix/nvm-install-cn/raw/main/uninstall.sh)" ``` > 卸载脚本会: > - 🗑️ 删除 `~/.nvm` 目录(包含所有 Node 版本) > - 🧹 清理 shell 配置文件中的相关配置 > - 💾 自动备份配置文件 > - 🔄 重启 shell 使更改生效 --- ## 💡 推荐配合工具 | 工具 | 特点 | 安装方式 | |------|------|----------| | [fnm](https://github.com/Schniz/fnm) | Rust 实现、速度快 | `brew install fnm` | | [Volta](https://volta.sh) | 智能版本管理、稳定性强 | `curl https://get.volta.sh | bash` | | [pnpm](https://pnpm.io) | 节省磁盘空间、极速包管理 | `corepack enable && corepack prepare pnpm@latest --activate` | --- ## 🧩 环境支持矩阵 | 系统 | 状态 | 说明 | |------|------|------| | macOS Intel | ✅ | 已测试通过 | | macOS Apple Silicon (M1/M2/M3) | ✅ | 自动识别架构 | | Ubuntu / Debian / CentOS | ✅ | 仅需 git | | Windows(WSL) | ✅ | 推荐 zsh 环境 | | Windows 原生 | ⚠️ | 请使用 [nvm-windows](https://github.com/coreybutler/nvm-windows) | --- ## 🧑‍💻 作者与项目 - **作者**:志辉 - **邮箱**: - **GitHub**:https://github.com/iamzhihuix/nvm-install-cn - **Gitee**:https://gitee.com/iamzhihuix/nvm-install-cn --- ## 🪄 License MIT License © 2025 志辉