After running this script, you will be able run npm install -g without sudo, becausenpm will install packages as your non-root user. The script will set up npm user directories for you, and then add them to your $PATH.

Packages can then be installed without root privileges:

$ npm install -g yarn
$ type yarn
yarn is /home/user/.npm-packages/bin/yarn


Run the following:

$ curl -s "" | bash

You can check out the script’s requirements here.


The script takes 6 optional positional arguments, or you can set environment variables:

Position Variable name Description Default value
1 $ROOT The root directory for npm $HOME
2 $SHELL_NAME Name of the shell to configure Current shell
3 $SHELL_RC Shell configuration file, automatically detected $HOME/.profile
4 $BIN npm’s executable directory $ROOT/.npm-packages/bin
5 $MAN Manpage directory for npm $ROOT/.npm-packages/share/man
6 $REINSTALL Set to any non-null value to reinstall old npm packages in your new $ROOT Unset

Passing options

If you want to set your npm path to ~/.local/.npm-packages, instead of ~/.npm-packages, and configure zsh to work with it, you can run:

$ export URL=""
$ curl -s "$URL" | bash -s "~/.local" "zsh"

You can also use environment variables:

$ export ROOT="~/.local" SHELL_NAME="zsh"
$ curl -s "$URL" | bash

Confirming it works

Install a package with the global flag -g and then see where npm puts the files:

$ npm install -g yarn
$ type yarn
yarn is /home/user/.npm-packages/bin/yarn


Click here to see the dependencies and supported systems for this script


  • Bash, GNU Coreutils and grep
  • curl
  • NPM

Supported systems


This script works with configuration files for the following shells:

  • bash
  • zsh
  • fish
  • sh

The script will default to $HOME/.profile if it doesn’t recognize any of the shells from above. ksh uses $HOME/.profile, but the script wasn’t tested on it.

Operating systems

This script will work on any POSIX compatible system or compatibility layer.

  • Linux
  • *BSD
  • macOS
  • WSL 1 & 2 on Windows
  • Cygwin or MSYS2 on Windows


You can check out the script on GitHub via the 🏠 npm-user project.

Click here to show 🏠 npm-user source code below