Multi-User NodeJS Environment

Published: March 06, 2018 Last Updated: Author: Saad Ali

WARNING! Following this article, improvise if necessary. Your environment may be different than mine. I am not responsible if you screw up!

This tutorial helps setup a NodeJS local environment on Debian/Ubuntu. Using a local environment, a developer can install node modules via npm command locally in his home directory. That way, the NodeJS installation on the OS is untouched and users still get what they want without granting them sudo access. You could use it for other Linux/BSD distributions but this has only been tested on Debian Jessie and Stretch.

Install NodeJS

We'll begin by installing NodeJS via official repository:

# curl -sL | bash -
# apt-get install -y nodejs

Modify Skeleton

Create .npm directory in /etc/skel:

# mkdir /etc/skel/.npm

Add following lines to /etc/skel/.profile or /etc/skel/.bashrc:

# set NPM directory

# set PATH to include local NPM directory
#if [ -d "$NPM_DIR" ] ; then

# Unset manpath so we can inherit from /etc/manpath via the `manpath` command
unset MANPATH  # delete if you already modified MANPATH elsewhere in your configuration

# Tell Node about these packages

Create .npmrc in /etc/skel with the following line:

prefix = ${HOME}/.npm

After these modifications are made, you can create new users. The new users can then use npm command to install NodeJS modules.

Optionally, if you already have NodeJS installed system-wide, you can make these modifications in your own home directory and source either .profile or .bashrc (which ever you have modified).


Tagged as: Linux, NodeJS, Debian, Ubuntu