在國內使用 npm 時,由于網絡限制可能會遇到下載速度慢或連接超時的問題。通過設置國內鏡像源,可以顯著提升下載速度和穩定性。以下是常用的國內 npm 鏡像源及其配置方法。
查詢當前使用的鏡像源
npm get registry
設置為淘寶鏡像源?
npm config set registry https://registry.npmmirror.com/
驗證設置
npm get registry
還原為官方源
npm config set registry https://registry.npmjs.org/?
國內常用鏡像源
-
淘寶鏡像?地址:?https://registry.npmmirror.com/?配置命令:
npm config?set?registry https://registry.npmmirror.com/
-
阿里云鏡像?地址:?https://npm.aliyun.com/?配置命令:
npm config?set?registry https://npm.aliyun.com/
-
騰訊云鏡像?地址:?https://mirrors.cloud.tencent.com/npm/?配置命令:
npm config?set?registry https://mirrors.cloud.tencent.com/npm/
-
華為云鏡像?地址:?https://mirrors.huaweicloud.com/repository/npm/?配置命令:
npm config?set?registry https://mirrors.huaweicloud.com/repository/npm/
-
清華大學開源鏡像站?地址:?https://mirrors.tuna.tsinghua.edu.cn/npm/?配置命令:
npm config?set?registry https://mirrors.tuna.tsinghua.edu.cn/npm/
查看與驗證當前鏡像源
-
查看當前使用的鏡像源:
npm config get registry
-
驗證是否設置成功:
npm info express
快速切換鏡像工具:nrm
nrm?是一個 npm 源管理工具,可以快速切換不同的鏡像源。
-
安裝 nrm:
npm?install?-g nrm
-
查看可用鏡像源:
nrm?ls
-
切換到指定鏡像源(如淘寶):
nrm use taobao
-
測試各鏡像源速度:
nrm?test
參考:npm 最新國內鏡像源設置 2025 - 工程師焱記 - 博客園