Why use sudo to install node-red via npm?

Hi! I just heard Nick O'Leary on the JS Party podcast and am excited to try out Node-RED.

Why is using sudo the recommended method for npm installing on local computers? This recommendation used to be frequent some time ago, but over the last few years I've seen this trend go away.

Curious as to why the authors recommend this (I've never quite understood the implications one way or the other).

Hi @brianzelip

it depends largely on how your node environment is setup.

In many default installs of node.js, global modules are put under /usr/lib (or similar). That is a space you usually require administrative/root access in order to write to.

So to install node-red as a global module, you need to use sudo in order to be able to install there, as sudo runs the command with administrative privileges.

But if you use something like nvm to manage your local node install, then global modules are stored somewhere the regular user can write to, so you don't need to use sudo.

1 Like