一 npm升级版本:
[root@izbp1845cet96se1qmb5ekz ~]# npm install -g npm
二 npm 更改加速源
默认的 npm 源为:https://registry.npmjs.org/
[root@izbp1845cet96se1qmb5ekz ~]# npm config get registry
https://registry.npmjs.org/
npm更改加速源为 淘宝镜像源
[root@izbp1845cet96se1qmb5ekz ~]# npm config set registry https://registry.npm.taobao.org
[root@izbp1845cet96se1qmb5ekz ~]# npm config get registry
https://registry.npm.taobao.org/
[root@izbp1845cet96se1qmb5ekz ~]#
npm更改加速源为 华为云镜像源
[root@izbp1845cet96se1qmb5ekz ~]# npm config set registry https://mirrors.huaweicloud.com/repository/npm
[root@izbp1845cet96se1qmb5ekz ~]# npm config get registry
https://mirrors.huaweicloud.com/repository/npm
[root@izbp1845cet96se1qmb5ekz ~]#
npm 改回为默认的 registry 镜像源:
[root@izbp1845cet96se1qmb5ekz ~]# npm config set registry https://registry.npmjs.org
[root@izbp1845cet96se1qmb5ekz ~]# npm config get registry
https://registry.npmjs.org/
三 切换镜像源
我们可以使用一些小工具进行切换镜像源 ,例如 nrm
[root@izbp1845cet96se1qmb5ekz ~]# npm install -g nrm
[root@izbp1845cet96se1qmb5ekz ~]# nrm ls
npm -------- https://registry.npmjs.org/
yarn ------- https://registry.yarnpkg.com/
cnpm ------- http://r.cnpmjs.org/
* taobao ----- https://registry.npm.taobao.org/
nj --------- https://registry.nodejitsu.com/
npmMirror -- https://skimdb.npmjs.com/registry/
edunpm ----- http://registry.enpmjs.org/
[root@izbp1845cet96se1qmb5ekz ~]# nrm use yarn // npm加速镜像源变为了yarn源
Registry has been set to: https://registry.yarnpkg.com/
[root@izbp1845cet96se1qmb5ekz ~]#
[root@izbp1845cet96se1qmb5ekz ~]# npm config get registry // npm加速镜像源变为了yarn源
https://registry.yarnpkg.com/
四 使用更快的 registry 镜像
使用更快的 registry 镜像。常用的方法主要分为两类:
第一类:配置文件法: (效果同 三.切换镜像源)
npm config set registry https://registry.npm.taobao.org
第二类: 直接用第三方的npm
npm install -g cnpm --registry=https://registry.npm.taobao.org # 使用 --registry参数指定镜像服务器地址
# 接下来直接使用 cnpm ,不是用npm了
cnpm install