The “EACCES” is one of the errors typically encountered when you are trying to install a global npm package like ‘npm install lodash’ in a system or trying to access a file or folder that does not have the necessary permissions to access it. Although there can be many reasons for the occurrence of the error “EACCES: permission denied“, let’s understand why this error is encountered and how to fix it so that your application runs perfectly.
Common causes of “Error: EACCES: permission denied”
Below are the common causes where you might encounter this error-
- Insufficient file or directory permissions.
- Running your application as the wrong user.
- Mistyped or inaccurate file paths.
- Incorrect Ownership of file or directory.
- Additional security restrictions.
How to resolve the error “EACCES: permission denied”?
Following are the two solutions to resolve the EACCES error when you are trying to install a package globally.
- Firstly you can do is Reinstall npm with the node version manager
OR - Another thing you can do is manually change npm’s default directory.
Steps to Reinstall npm with a node version manager
- Install NVM (Node Version Manager).
- Install the desired version of Node.js:
nvm install node - Reinstall npm:
npm install -g npm - Verify the installations:
node -v
npm -v
Steps to Manually change npm’s default directory
- Firstly take a Back up of your computer.
- Then create a directory for global installations by using the given command.
mkdir ~/.npm-global - Set npm to use the new directory path by using the given command.
npm config set prefix ‘~/.npm-global’ - Open or create the ~/.profile file by using the given command.
export PATH=~/.npm-global/bin:$PATH - Update system variables by using the given command.
source ~/.profile - Test the configuration by using the given command.
npm install -g jshint
Instead of steps 3-5, you can use the corresponding ENV variable (e.g. if you don’t want to modify ~/.profile):
NPM_CONFIG_PREFIX=~/.npm-global