温馨提示×

ubuntu nodejs怎么设镜像

小樊
40
2026-10-03 21:01:01
栏目: 编程语言

在 Ubuntu 上给 Node.js 设置镜像,通常是指给 npm 或 Node 本身配置国内镜像源(比如淘宝镜像),加快下载速度。下面按常见场景给你说明:


一、给 npm 设置镜像(最常用)

1️⃣ 临时使用(只对当前命令有效)

npm install xxx --registry=https://registry.npmmirror.com

2️⃣ 永久设置 npm 镜像(推荐)

npm config set registry https://registry.npmmirror.com

查看是否设置成功:

npm config get registry

输出应为:

https://registry.npmmirror.com

二、恢复官方镜像

npm config set registry https://registry.npmjs.org

三、使用 nrm 管理镜像(方便切换)

npm install -g nrm
nrm ls
nrm use npmmirror

四、如果是用 nvm 管理 Node 版本

nvm 本身不需要镜像,但安装 Node 时可加速:

export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node
nvm install 18

或写入 ~/.bashrc / ~/.zshrc:

echo 'export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node' >> ~/.bashrc
source ~/.bashrc

五、yarn 设置镜像(如果你用 yarn)

yarn config set registry https://registry.npmmirror.com

六、pnpm 设置镜像

pnpm config set registry https://registry.npmmirror.com

✅ 推荐组合(国内环境)

  • npm / pnpm / yarn → https://registry.npmmirror.com
  • Node 安装 → npmmirror.com/mirrors/node

如果你能告诉我:

  • 用的是 npm / yarn / pnpm
  • Node 是 apt 安装 / nvm / 二进制

我可以给你更精确的步骤。

0 踩