在 Debian 系统上配置 npm 镜像(通常使用国内镜像如淘宝 npm 镜像)有几种常见方式,下面按推荐程度给你介绍。
只在某一次安装时指定:
npm install <package> --registry=https://registry.npmmirror.com
npm config set registry https://registry.npmmirror.com
旧地址
https://registry.npm.taobao.org已废弃,请使用上面的新地址。
npm config get registry
npm config set registry https://registry.npmjs.org
.npmrc 文件配置(适合多用户/项目)编辑或创建:
nano ~/.npmrc
内容:
registry=https://registry.npmmirror.com
在项目根目录新建 .npmrc:
registry=https://registry.npmmirror.com
npm install -g nrm
nrm use npmmirror
查看可用镜像:
nrm ls
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
不要使用 sudo npm -g,推荐:
npm config set prefix ~/.npm-global
export PATH=~/.npm-global/bin:$PATH
npm ping
返回类似:
Ping success: 123ms
如果你是在 Docker / CI / 特定 Debian 版本 下使用,也可以告诉我,我可以给你更具体的配置方案。