How to Fix npm EACCESS Permission Denied Error
The solution…
Ever tried installing packages globally and encountered an EACCES permissions error? For instance, running the following command ‘npm install -g expo-cli’ returns you with —
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied… … ….
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! If you believe this might be a permissions issue, please double-check the permissions of the file and its containing directories, or try running the command again as root/Administrator.
The Solution —
- Reinstall npm with a version manager, OR
- Do a manual change of npm’s default directory
To download and install the latest version of npm, run the following commands:
npm install -g npm
To manually change npm’s default directory, run the following commands:
mkdir ~/.npm-global
npm config set prefix ‘~/.npm-global’
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
OR
mkdir ~/.npm-global
npm config set prefix ‘~/.npm-global’
echo ‘ export PATH=~/.npm-global/bin:$PATH’ >> ~/.bash_profile
source ~/.bash_profile
→Run these commands to check for the installed versions:
npm -v
node -v