推荐永久配置淘宝镜像(https://registry.npmmirror.com)以提升国内 npm install 速度,执行 npm config set registry https://registry.npmmirror.com 即可生效。

在 JavaScript 项目中,用 npm install 下载依赖时,默认走的是 npm 官方源(https://www.php.cn/link/f3a22d6edd297a48ac3189878051a52f),国内访问慢、容易超时或失败。配置淘宝镜像(现由 npmmirror.com 提供)能显著提升下载速度。
查看当前 registry 地址
执行以下命令确认当前使用的源:
npm config get registry如果返回 https://www.php.cn/link/f3a22d6edd297a48ac3189878051a52f,说明还没切到国内镜像。
临时使用淘宝镜像(单次生效)
只对当前这条命令生效,不影响全局设置:
立即学习“Java免费学习笔记(深入)”;
npm install --registry https://registry.npmmirror.com也可以简写为:
npm install -r https://registry.npmmirror.com永久切换为淘宝镜像(推荐)
运行以下任一命令,将默认 registry 永久设为淘宝镜像:
- npm config set registry https://registry.npmmirror.com
- 或使用别名(更简洁):npm config set registry https://r.cnpmjs.org(该地址仍可访问,但官方推荐用
npmmirror.com)
设置后,所有 npm install 都会自动走镜像源。可用 npm config get registry 验证是否生效。
还原为官方源(可选)
如需切回 npm 官方源:
npm config set registry https://www.php.cn/link/f3a22d6edd297a48ac3189878051a52f不复杂但容易忽略,配一次就能长期受益。



















