快速设置 npm 源

1. 使用 nrm 工具(最推荐)

安装 nrm

复制代码
npm install -g nrm

查看并测试所有源的速度

复制代码
# 查看可用源
nrm ls

# 测试各个源响应速度
nrm test

切换到最快的源

复制代码
# 根据测试结果选择最快的源
nrm use taobao        # 淘宝源(国内最快)
# 或
nrm use huawei        # 华为云源
# 或
nrm use tencent       # 腾讯云源

2. 直接修改 npm 配置

切换到淘宝源(推荐)

复制代码
npm config set registry https://registry.npmmirror.com/

切换到华为云源

复制代码
npm config set registry https://mirrors.huaweicloud.com/repository/npm/

切换到腾讯云源

复制代码
npm config set registry https://mirrors.cloud.tencent.com/npm/

3. 验证源是否修改成功

复制代码
npm config get registry

4. 国内常用镜像源推荐

源名称 地址 特点
淘宝源 https://registry.npmmirror.com/ 国内最流行,同步速度快
华为云源 https://mirrors.huaweicloud.com/repository/npm/ 稳定快速
腾讯云源 https://mirrors.cloud.tencent.com/npm/ 腾讯云用户推荐

5. 临时使用特定源(不修改配置)

复制代码
npm install 包名 --registry=https://registry.npmmirror.com/

6. 恢复官方源

复制代码
npm config set registry https://registry.npmjs.org/

⭐ 推荐方案

直接使用淘宝源,这是国内最稳定快速的:

复制代码
npm config set registry https://registry.npmmirror.com/

如果你经常需要切换不同源进行测试,建议安装 nrm 工具,可以很方便地管理和切换源。

相关推荐
无羡仙1 天前
Vue插槽
前端·vue.js
Cosimac1 天前
用 npm 做免费图床,这操作绝了!
npm·github
用户6387994773051 天前
每组件(Per-Component)与集中式(Centralized)i18n
前端·javascript
SsunmdayKT1 天前
React + Ts eslint配置
前端
奶糖的次元空间1 天前
带你用 Javascript 生成器玩转「会暂停」的函数
node.js
开始学java1 天前
useEffect 空依赖 + 定时器 = 闭包陷阱?count 永远停在 1 的坑我踩透了
前端
zerosrat1 天前
从零实现 React Native(2): 跨平台支持
前端·react native
狗哥哥1 天前
🔥 Vue 3 项目深度优化之旅:从 787KB 到极致性能
前端·vue.js
青莲8431 天前
RecyclerView 完全指南
android·前端·面试
青莲8431 天前
Android WebView 混合开发完整指南
android·前端·面试