npm无法使用sudo运行

时间:2019-10-02 19:11:10

标签: node.js npm sudo

我在Amazon EC2节点(弹性豆秆)上,如果我运行npm,则会得到:

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

Specify configs in the ini-formatted file:
    /home/ec2-user/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@6.11.3 /home/ec2-user/.nvm/versions/node/v12.11.1/lib/node_modules/npm

但是如果我运行sudo npm,我会得到:

sudo: npm: command not found

我需要使用sudo来使脚本正常工作。

1 个答案:

答案 0 :(得分:-1)

通常,当root用户的shell设置中没有相应的可执行路径(PATH变量)时,会发生这种情况。如果使用Bash,则可以编辑/etc/profile来设置为每个登录Shell执行的所有用户的环境设置。