0

If i try to run this command bash respond with not found error:

$ npm -v
-bash: npm: command not found

with sudo also:

$ sudo npm -v
sudo: npm: command not found

but works when I run first a "sudo su":

$ sudo su
# npm -v
6.10.3

Why this happens? how can I fix it to works with sudo command?

Some info:

type npm
npm is /root/.nvm/versions/node/v12.10.0/bin/npm
which npm
/root/.nvm/versions/node/v12.10.0/bin/npm
3
  • Please run sudo su and then type npm and which npm and add the output to the question.
    – pLumo
    Mar 5, 2020 at 15:57
  • 1
    How did you install npm ? Seems you installed it manually in your root directory. That is not available from your normal user, and not available in your PATH.
    – pLumo
    Mar 5, 2020 at 16:06
  • 1
    This looks like expected behavior when you (unwisely) install an application into /root instead of one of the usual locations.
    – user535733
    Mar 5, 2020 at 16:08

1 Answer 1

1

Login as root:

sudo su -

Uninstall npm via nvm:

nvm deactivate node && nvm uninstall node

Install npm via apt-get:

apt-get update && apt-get install npm

Obviously you had npm installed via nvm. nvm is a user-based package manager. Therefor all installed packages will not be available for other users. The solution is to use a package manager which installs packages globally on a system-basis.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .