[node.js] Error: EACCES: permission denied

I run npm install lodash but it throws Error: EACCES: permission denied error. I know it is permission issue but as far as I know, sudo permission is not required for installing node module locally. If I run it with sudo, it gets installed inside ~/node_modules folder. drwxrwxr-x is the file permission of existing folder. I can't figure out what might have gone wrong.

Below is the error message.

npm ERR! tar.unpack untar error /home/rupesh/.npm/lodash/4.13.1/package.tgz
npm ERR! Linux 3.13.0-88-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "lodash"
npm ERR! node v4.3.1
npm ERR! npm  v2.14.12
npm ERR! path /home/rupesh/node_modules/lodash
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir

npm ERR! Error: EACCES: permission denied, mkdir '/home/rupesh/node_modules/lodash'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, mkdir '/home/rupesh/node_modules/lodash']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/home/rupesh/node_modules/lodash',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/home/rupesh/node_modules/lodash',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:35:25',
npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:47:53',
npm ERR!      'FSReqWrap.oncomplete (fs.js:82:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/rupesh/Desktop/es6/npm-debug.log

This question is related to node.js lodash

The answer is


A related issue:

Wasted 3 hours spanning several days.

On a AWS EC2 machine, below worked:

sudo chown -R $(whoami) /home/ubuntu/.cache
sudo chown -R $(whoami) /home/ubuntu/.config
sudo chown -R $(whoami) /home/ubuntu/.local
sudo chown -R $(whoami) /home/ubuntu/.npm
sudo chown -R $(whoami) /home/ubuntu/.pm2

Hope that helps.


If you getting an error like below

Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/<PackageName>/vendor'

I suggest using the below command to install your global package

sudo npm install -g <PackageName> --unsafe-perm=true --allow-root

I had problem on Linux. I wrote

chown -R myUserName /home/myusername/myfolder

in my project folder.

WARNING: this is NOT the right way to fix it; DO NOT RUN IT, if you aren't sure of what could be the consequences.


Try using this: On the command line, in your home directory, create a directory for global installations:

mkdir ~/.npm-global

Configure npm to use the new directory path:

npm config set prefix '~/.npm-global'

In your preferred text editor, open or create a ~/.profile file and add this line:

export PATH=~/.npm-global/bin:$PATH

On the command line, update your system variables:

source ~/.profile

Test installing package globally without using sudo, Hope it helps


Here's the solution for GNU/Linux (Debian) users (Replace USERNAME with your username):

sudo chown -R $USER:$(id -gn $USER) /home/USERNAME/.config


On Windows it ended up being that the port was already in use by IIS.

Stopping IIS (Right-click, Exit), resolved the issue.


This command fix the issue. It worked for me:

sudo npm install -g --unsafe-perm=true --allow-root

I have same issue with webpack server installation on globally, Use steps from this Url Solved my issue, my be work for you.

Steps mention above There: Back-up your computer before you start.

Make a directory for global installations:

1. mkdir ~/.npm-global

Configure npm to use the new directory path:

2.npm config set prefix '~/.npm-global'

Open or create a ~/.profile file and add this line:

3.export PATH=~/.npm-global/bin:$PATH

Back on the command line, update your system variables:

4.source ~/.profile

Test: Download a package globally without using sudo.

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 ~/.profile):

NPM_CONFIG_PREFIX=~/.npm-global

From what i can see in your logs you posted:

npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/home/rupesh/node_modules/lodash',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/home/rupesh/node_modules/lodash',
npm ERR!   fstream_class: 'DirWriter',

directory /home/rupesh/node_modules/ doesn't have necessary permissions to create directory so run chown -r rupesh:rupesh /home/rupesh/node_modules/ this should solve it.


Opening CMD(Windows WSl in this case) as Administrator worked out for me.I am using NodeJS Version 14.15.1


This solved my issue straight away - mac Mojave 10.14.6 - PhpStorm.

Unhandled rejection Error: EACCES: permission denied, mkdir '/Users/myname/.npm/_cacache/index-v5/fb/5a'

sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config

Original post: https://stackoverflow.com/a/50639828


Remove dist folder and this solve my problem!!


FWIW I had the same symptoms, but with a different package. Creating package.json and running npm init did NOT solve my issue.

On this system, apparently new folders in this location were being created with root permissions. During npm install, new folders are created. This caused npm install to fail partway, even with sudo.

The solution was to run npm install app in a different location with no root umask.


I tried most of these suggestions but none of them worked. Then I ran npm clean-install and it solved my issues.


Execute these commands and issue will be solved!

sudo chmod -R 777 /usr/local/bin
sudo chmod -R 777 /usr/local/lib/node_modules

It doesn't have write permissions for others (r-x). Try with

chmod a+w <folder>

and repeat.


node recommends executing following:

 sudo chown -R $USER:$(id -gn $USER) /home/venkatesh/.config

If you execute

npm config

You will see something like this

¦                   npm update check failed                   ¦
¦             Try running with sudo or get access             ¦
¦            to the local update config store via             ¦
¦ sudo chown -R $USER:$(id -gn $USER) /home/venkatesh/.config ¦

It worked for me.


LUBUNTU 19.10 / Same issue running: $ npm start

dump: Error: EACCES: permission denied, open '/home/simon/xxx/pagebuilder/resources/scripts/registration/node_modules/.cache/@babel/register/.babel.7.4.0.development.json' at Object.fs.openSync (fs.js:646:18) at Object.fs.writeFileSync (fs.js:1299:33) at save (/home/simon/xxx/pagebuilder/resources/scripts/registration/node_modules/@babel/register/lib/cache.js:52:15) at _combinedTickCallback (internal/process/next_tick.js:132:7) at process._tickCallback (internal/process/next_tick.js:181:9) at Function.Module.runMain (module.js:696:11) at Object. (/home/simon/xxxx/pagebuilder/resources/scripts/registration/node_modules/@babel/node/lib/_babel-node.js:234:23) at Module._compile (module.js:653:30) at Object.Module._extensions..js (module.js:664:10) at Module.load (module.js:566:32)

Looks like my default user (administrator) didn't have rights on node-module directories.

This fixed it for me!

$ sudo chmod a+w node_modules -R ## from project root


First install without -g (global) on root. After try using -g (global) It worked for me.


I solved this issue by changing the permission of my npm directory. I went to the npm global directory for me it was at

/home/<user-name>

I went to this directory by entering this command

cd /home/<user-name>

and then changed the permission of .npm folder by entering this command.

sudo chmod -R 777 ".npm"

It worked like a charm to me. But there is a security flaw with this i.e your global packages directory is accessible to all the levels.


Try to give all permission to your project folder with below command

sudo chmod -R 777 /yourProjectDirectoryName

run with

sudo npm install lodash

Just change the owner of the global node_modules directory to be your user:

sudo chown -R $USER:$GROUP /usr/local/lib/node_modules