If you see an
EACCES error when you try to install a package globally, read this chapter. This error can be avoided if you change the directory where npm is installed. To do this, either:
Reinstall npm with a version manager (recommended),
Change npm's default directory manually.
If you are using npm version 5.2 or greater, explore tools such as npx to circumvent permissions issues.
This is the best way to avoid permissions issues. This is described in Chapter 2. You do not need to remove your current version of npm or Node.js before installing a node version manager.
This section does not apply to Microsoft Windows. The chapter will be updated to address Windows in the near future.
To minimize chances of permissions errors, you can configure npm to use a different directory. In this example, it will be a hidden directory on your home folder.
Back-up your computer before moving forward.
Make a directory for global installations:
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a
~/.profile file and add this line:
Back on the command line, update your system variables:
Test: Download a package globally without using
npm install -g jshint
Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don't want to modify
Click here to read an excellent article about npx.
Last modified December 22, 2017 Found a typo? Send a pull request!