Skip to content

Instantly share code, notes, and snippets.

@iRynoh
Last active July 11, 2019 19:03
Show Gist options
  • Save iRynoh/58d82a98843d62c885278b6d0b3d046a to your computer and use it in GitHub Desktop.
Save iRynoh/58d82a98843d62c885278b6d0b3d046a to your computer and use it in GitHub Desktop.
NPM Global

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment