npm 官网镜像无法连接怎么办?

阿里云产品限时红包,最高 ¥1888 元,立即领取

在安装 Hexo 是需要先安装 Node.js,这个过程中会因为 npm 无法连接到官方 registry 而导致失败。

后来在网上搜到有淘宝的镜像,具体的配置方法有如下几种:

1. 通过 config 命令

1
2
npm config set registry https://registry.npm.taobao.org 
npm info underscore //如果上面配置正确这个命令会有字符串response

2. 命令行指定

1
npm --registry https://registry.npm.taobao.org info underscore

3. 编辑 ~/.npmrc 加入下面内容

1
registry = https://registry.npm.taobao.org

第三种方案只需配置一次。

原文:使用npm安装一些包失败了的看过来(npm国内镜像介绍)