If you see an
EACCES error when you try to install a package globally, read this chapter. This error can often 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.
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. This chapter will be updated to address Windows in the near future.
To minimize the chance 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 you start.
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
If you are using npm version 5.2 or greater, explore npx as an alternative way to run global commands, especially if you just need a command occassionally. Click here to read an excellent article about npx.
Last modified March 01, 2021 Found a typo? Send a pull request!