自从上次在Vmware中成功安装Manjaro, 我感觉用来作为敲代码的环境还是非常舒服的.
但今天在尝试在Linux下使用NPM创建Angular项目的时候, 出现了问题 - 无法改变默认的npm的默认registry.
经过我的实验, 单纯使用
npm config set registry <https://registry.npm.taobao.org>
是无法起到彻底更改registry的效果的. 即便之后执行命令
npm config get registry
时显示registry为你设置的源.
正确姿势:
在shell中执行npm命令, 有如下结果
[zrh-vmwarevirtualplatform ~]# npm
npm <command>
Usage:
npm install install all the dependencies in your project
npm install <foo> add the <foo> dependency to your project
npm test run this project's tests
npm run <foo> run the script named <foo>
npm <command> -h quick help on <command>
npm -l display usage info for all commands
npm help <term> search for help on <term>
npm help npm more involved overview
All commands:
access, adduser, audit, bin, bugs, cache, ci, completion,
config, dedupe, deprecate, diff, dist-tag, docs, doctor,
edit, exec, explain, explore, find-dupes, fund, get, help,
hook, init, install, install-ci-test, install-test, link,
ll, login, logout, ls, org, outdated, owner, pack, ping,
prefix, profile, prune, publish, rebuild, repo, restart,
root, run-script, search, set, set-script, shrinkwrap, star,
stars, start, stop, team, test, token, uninstall, unpublish,
unstar, update, version, view, whoami
Specify configs in the ini-formatted file:
**/root/.npmrc**
or on the command line via: npm <command> --key=value
More configuration info: npm help config
Configuration fields: npm help 7 config
npm@7.9.0 /usr/lib/node_modules/npm
[zrh-vmwarevirtualplatform ~]#
其中一个很重要的点就是: /root/.npmrc, 这是npm为用户自定义npm而预留的配置文件. 可以通过修改.npmrc来对registry进行配置.
不过这个配置文件在系统中默认可能是不存在的, 因此需要自己手动创建
vim /root/.npmrc
然后在vim中输入:
registry=https://registry.npm.taobao.org/
保存.
今后使用npm的时候registry就不会是默认的了.