A
A
Alexey Yarkov2017-03-12 00:33:31
npm
Alexey Yarkov, 2017-03-12 00:33:31

Why does npm need sudo?

I go to VPS:

[email protected]:[~]$ npm config get prefix
/home/vpsuser/.nvm/versions/node/v7.6.0
[email protected]:[~]$ npm install [email protected] -g
......... Все ОК .........

But if I install a package that has the following in package.json:
"scripts": {
    "preinstall": "npm i -g pm2 apidoc jsdoc eslint babel-cli"
  }

Then the package installation crashes with an access rights error. But if you write:
"scripts": {
    "preinstall": "sudo npm i -g pm2 apidoc jsdoc eslint babel-cli"
  }

then everything is ok ... How is this to be understood?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
afishr, 2017-03-12
@afishr

I don’t think I will open America to anyone, but if npm packages are installed globally (key -g), then they are installed in system directories, and this requires superuser rights.

A
AdaStreamer, 2017-03-12
@AdaStreamer

It's all about the -g switch, which says that the package must be installed globally in the system.
"preinstall": "npm i pm2 apidoc jsdoc eslint babel-cli"
will work as you would expect

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question