1.通过config命令
npm config set registry https://registry.npm.taobao.org
npm config list #查看npm当前配置
2.命令行指定
每次执行命令前加入–registry指定仓库路径
npm --registry https://registry.npm.taobao.org install
3.编辑 ~/.npmrc 加入下面内容
registry = https://registry.npm.taobao.org
$ npm adduser
Username: your name
Password: your password
Email: yourmail[@gmail](/user/gmail).com
如果出现以下错误,可能是你的npm版本太低,通过sudo npm install -g npm
升级一下。
npm WARN adduser Incorrect username or password
npm WARN adduser You can reset your account by visiting:
npm WARN adduser
npm WARN adduser http://admin.npmjs.org/reset
npm WARN adduser
npm ERR! Error: forbidden may not mix password_sha and pbkdf2
npm ERR! You may need to upgrade your version of npm:
npm ERR! npm install npm -g
npm ERR! Note that this may need to be run as root/admin (sudo, etc.)
成功之后,npm会把认证信息存储在~/.npmrc
中,并且可以通过以下命令查看npm当前使用的用户:
$ npm whoami