According to Dan Dascalescu, Sindre Sorhus's guide is overkill.
Quoting archived version of Michael Bethencourt's guide (whose domain has expired at the time of writing):
The Right Way™ to do global npm install without sudo
[…]
Step 1: Configure NPM
npm config set prefix ~/.local
Now NPM will install your global executables to
~/.local/bin
, and the libraries to~/.local/lib/node_modules/
Step 2: Add
~/.local/bin
to your pathIf you haven't already, open up the conf file of your favorite shell (such as
~/.bashrc
for Bash), and add in:PATH=~/.local/bin/:$PATH
That's it. You're done.
[…]
Don't forget to source ~/.bashrc
(or restart the terminal).