由于众所周知的原因,在国内使用 NPM 非常麻烦。将源设置为国内镜像(比如淘宝),就能正常使用 npm install 了。
1 |
npm config set registry http://registry.npm.taobao.org/ |
除此之外,还有一些国外的 NPM 镜像。各个镜像各自都可能有少数包暂时没有同步,有时候就会需要切换 NPM 镜像,或者使用内部镜像。相比每次切换时都手动指定相应参数,使用 NRM 要方便的多。
NRM 项目地址:https://github.com/Pana/nrm
安装方法:
1 |
$ npm install -g nrm |
列出可用镜像:
1 2 3 4 5 6 7 8 |
$ nrm ls * npm ----- https://registry.npmjs.org/ cnpm ---- http://r.cnpmjs.org/ taobao -- http://registry.npm.taobao.org/ nj ------ https://registry.nodejitsu.com/ rednpm -- http://registry.mirror.cqupt.edu.cn skimdb -- https://skimdb.npmjs.com/registry |
切换镜像:
1 2 3 |
$ nrm use taobao Registry has been set to: http://registry.npm.taobao.org/ |
测试源速度:
1 2 3 |
$ nrm test taobao * taobao - 218ms |
测试所有源速度:
1 2 3 4 5 6 7 8 |
$ nrm test npm ---- 348ms cnpm --- 301ms * taobao - 140ms nj ----- Fetch Error rednpm - 222ms npmMirror 1208ms |
添加自定义镜像源:
1 |
nrm add <registry> <url> [home] |
其他使用方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Usage: nrm [options] [command] Commands: ls list all the registries use <registry> change registry to registry add <registry> <url> [home] add one custom registry del <registry> delete one custom registry home <registry> [browser] open the homepage of registry with optional browser test [registry] show the response time for one or all registries help print this help Options: -h, --help output usage information -V, --version output the version number |
- 本文固定链接: https://blog.kuoruan.com/105.html
- 转载请注明: Index 于 扩软博客 发表
捐 赠如果您觉得这篇文章有用处,请支持作者!鼓励作者写出更好更多的文章!
npm install无法使用时快速切换 NPM 镜像源 | 扩软博客 http://situspokerdamai.co