Node.js & NPM on a multi-user-machine

761 views
Skip to first unread message

Sebastian Sester

unread,
Jun 13, 2014, 10:06:57 AM6/13/14
to nod...@googlegroups.com
Dear all,

I'm trying to set up Node.js and NPM on a multi-user-machine so it can be used for all users without requiring sudo.
I followed the instructions for backporting Node to Wheezy [0] and am now able to run nodejs (and node) for all users.
Since I do need npm, too, I did as recommended and used the install script given on the website.

But since npm gets installed to /usr/local, I can't execute it without sudo. Also, changing the ownership of /usr/local/… to my user (as often suggested) won't help, since other users need to access it, too.

Is there any documentation on how to do this correctly?

Thanks in advance,
Sebastian

Forrest Norvell

unread,
Jun 13, 2014, 11:26:39 AM6/13/14
to nod...@googlegroups.com

On Fri, Jun 13, 2014 at 7:06 AM, Sebastian Sester <sesters...@gmail.com> wrote:

since npm gets installed to /usr/local, I can't execute it without sudo. Also, changing the ownership of /usr/local/… to my user (as often suggested) won't help, since other users need to access it, too.

Because npm only needs elevated privileges when you’re installing packages globally (with -g / --global), and because you should only do that when you need binaries exposed by those packages to be available systemwide, you should only need to use sudo comparatively infrequently. Most of the time, npm installs packages into the closest node_modules directory. Are you running into a situation where this isn’t the case?

As an aside, you may want to build and install node from source. The Debian packaging of node is quirky, and using either the official binary tarball (if you don’t feel like installing build-essential) or building from source is likely to be more straightforward in the long run.

F

Sam Roberts

unread,
Jun 13, 2014, 12:16:42 PM6/13/14
to nod...@googlegroups.com
On Fri, Jun 13, 2014 at 11:25 AM, Forrest Norvell <othi...@gmail.com> wrote:
> On Fri, Jun 13, 2014 at 7:06 AM, Sebastian Sester
> <sesters...@gmail.com> wrote:
>>
>> since npm gets installed to /usr/local, I can't execute it without sudo.
>> Also, changing the ownership of /usr/local/… to my user (as often suggested)
>> won't help, since other users need to access it, too.
>
> Because npm only needs elevated privileges when you’re installing packages
> globally (with -g / --global), and because you should only do that when you

Also for `npm link`. Which should probably default to putting symlinks
in ~/.npm/links/, and support a `npm link -g`, for installing global
cli scripts as links to your dev env. Current scheme is an unfortunate
intermixing of global installs and links.

Sam

Sebastian Sester

unread,
Jun 13, 2014, 9:32:54 PM6/13/14
to nod...@googlegroups.com


Am Freitag, 13. Juni 2014 17:26:39 UTC+2 schrieb Forrest L Norvell:

Because npm only needs elevated privileges when you’re installing packages globally (with -g / --global) [...] Are you running into a situation where this isn’t the case?

I only can use the command as root; it simply says the command doesn't exist to other users. Which is because npm is installed in /usr/lib/node_modules/ and that directory is owned by root right after the script finished (i.e. I didn't set it like this):
drwxr-----  3 nobody root        4096 Jun 14 03:20 node_modules

And I just realized that when I fixed the group I obviously forgot to fix the rights themselves, too. :-(
(Just did that and it's working now as expected.)

As an aside, you may want to build and install node from source. The Debian packaging of node is quirky, and using either the official binary tarball (if you don’t feel like installing build-essential) or building from source is likely to be more straightforward in the long run.

I first tried to use the tarball but I got the same errors there and wasn't sure if it's my fault or not; that's the only reason why I switched to the debian repo.

Thanks a lot,
Sebastian

Sam Roberts

unread,
Jun 16, 2014, 1:27:34 AM6/16/14
to nod...@googlegroups.com
> Am Freitag, 13. Juni 2014 17:26:39 UTC+2 schrieb Forrest L Norvell:
>> As an aside, you may want to build and install node from source. The
>> Debian packaging of node is quirky, and using either the official binary

I agree with above (and I build from source, myself), but I've found
quality of https://launchpad.net/~chris-lea/+archive/node.js/ to be
excellent, and Chris appears to track node stable point releases close
to instantly, you want a .deb package, and can use ubuntu packages on
debian (I suspect you can), you might try that rather than official
deb/ubuntu packages, they lag way too far behind node stable.

Alexey Petrushin

unread,
Jun 17, 2014, 9:05:47 AM6/17/14
to nod...@googlegroups.com
Had similar problem while setting up Jenkins CI with Node.js. Ended up installing it locally for every user that needs it and altering path env variable.

Maybe there's better way, but in our case it was sufficient.
Reply all
Reply to author
Forward
0 new messages