npm和yarn更换源

npm安装

查看npm版本

npm -v

npm查看所有版本

npm view npm versions

npm更新到最新版

npm install -g npm

查看npm当前镜像源

npm config get registry

设置npm镜像源为淘宝镜像

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

遇到如下报错,是npm版本过低

Block-scoped declarations (let, const, function, class) not yet supported outside strict mode at

需要ubuntu升级npm和node

node -v
v4.2.6
npm -v
3.5.2

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs

node -v
v12.22.12
npm -v
6.14.16

npm安装项目依赖

npm install --dependencies

mac升级node,参考:Mac升级node14.17.2版本

清除nodejs的缓存

sudo npm cache clean -f

安装n模块

sudo npm install -g n

查看所有能安装的版本

npm view node versions

安装特定版本

sudo n 14.17.2

验证版本

node -v
v14.17.2

yarn安装

参考:Yarn for mac 安装教程

查看yarn版本

yarn -v

yarn查看所有版本

npm view yarn versions

yarn更新到最新版

npm install yarn@latest -g

yarn 升级指定版本

yarn upgrade v1.21.3

yarn 降低到指定版本(先卸载,再安装)

npm uninstall yarn -g
npm install -g yarn@1.3.2

查看yarn当前镜像源

yarn config get registry

设置yarn镜像源为淘宝镜像

yarn config set registry https://registry.npm.taobao.org/

镜像源地址

npm --- https://registry.npmjs.org/
cnpm --- https://r.cnpmjs.org/
taobao --- https://registry.npm.taobao.org/
nj --- https://registry.nodejitsu.com/
rednpm --- https://registry.mirror.cqupt.edu.cn/
npmMirror --- https://skimdb.npmjs.com/registry/
deunpm --- http://registry.enpmjs.org/

也可以在工程目录下添加 .npmrc 文件来指定该项目的源

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

 

posted @ 2016-10-11 22:03  tonglin0325  阅读(1363)  评论(0编辑  收藏  举报