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 
6

26 Answers

This command fix the issue. It worked for me:

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

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 
4

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.

5

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

sudo chmod -R 777 /yourProjectDirectoryName 

run with

sudo npm install lodash 
4

Creating package.json using npm init solved my issue.

3

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

chmod a+w <folder> 

and repeat.

4

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.

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:

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

1

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.

4
sudo chown -R $(whoami) /usr/local/bin 

Makes current user owner of the /usr/local/bin folder. Permissions on this folder were the trouble.

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 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.

2

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 
1

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

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

1

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

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

After trying anything, I followed this video from NPM. It solved for me smoothly!

Instructions as follow (on older Mac):

  1. In the terminal, inside your user directory, create this folder mkdir .npm-global. This will be the new folder where all your global NPM installations will go, instead of the default .npm which has permission issues.
  2. cd .npm-global/
  3. Run npm config set prefix /Users/your_user/.npm-global
  4. Set the Path for the system to know where to find the packages: Run vi ~/.profile. If you don't have this file, run touch ~/.profile first, then vi ~/.profile. Write export PATH=/Users/your_user/.npm-global/bin:$PATH at the very top. You could also open this file with a text editor (as it's a hidden file, use SHIFT + CMD + . to show it).
  5. Back to the terminal, inside the /.npm-global folder, run source ~/.profile

You should now be ready to install your package globally.

However, the above seems not to be working on newer OS, like BigSure.

This should solve:

sudo chown -R `whoami` ~/.npm sudo chown -R `whoami` /usr/local/lib/node_modules 

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

I tried a few of the answers from above on my Mac running Bigsur 11.4 and did not work. But what worked was the following instructions posted on npmjs docs website.

Remove dist folder and this solve my problem!!

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

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

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

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

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.

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

The permission denied error was persistent after all chown command. However, updating npm sudo npm install -g npm@8.3.2 and changing path to PATH="$PATH" worked for me.

You Might Also Like