Multi-User NodeJS Environment
Published: March 06, 2018 Last Updated: Author:
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 https://deb.nodesource.com/setup_6.x | 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
NPM_DIR="$HOME/.npm"
# set PATH to include local NPM directory
#if [ -d "$NPM_DIR" ] ; then
PATH="$NPM_DIR/bin:$PATH"
#fi
# 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
MANPATH="$NPM_DIR/share/man:$(manpath)"
# Tell Node about these packages
NODE_PATH="$NPM_DIR/lib/node_modules:$NODE_PATH"
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