When npm tries to install to globally, it tries to install it's packages to the sensible location of /usr/local/
. When you aren't a super user, this gives the warning checkPermissions Missing write access to /usr/local/lib
and error Error: EACCES: permission denied, access '/usr/local/lib'
and fails. Other package installers (such as Python's pip) already ship, at least on Ubuntu, with a concept of a user-specific local directory of ~/.local/
to replace the global /usr/local/
to avoid such warnings.
Thus, let's just reuse this existing convention.
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 path. If 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.