Error: EACCES: permission denied
Asked Answered
A

30

227

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
Arvell answered 12/7, 2016 at 8:41 Comment(6)
is the owner of the folder node_modules root?Rafa
node_module folder is not created yet inside folder in which i intend to install lodash.Arvell
did you run npm install in your /home/rupesh/ directory or some other directory?Rafa
path of folder in which I run npm install is ~/Desktop/es6Arvell
whats the output of ls -l ~/Desktop | grep es6 make sure you are the owner of es6 directoryRafa
drwxrwxrwx 3 rupesh rupesh 4096 Jul 12 14:48 es6Arvell
A
19

Creating package.json using npm init solved my issue.

Arvell answered 12/7, 2016 at 16:24 Comment(5)
But I am not sure why package.json file is required while installing node module as package.json file is not updated or used in my case because I have not used --save or --save-dev or similar command.Arvell
this is weird. i think some thing was messed up in your npm conf and doing init reset it, anyways it should be a mystery forever as i couldn't find a single reference to a similar problem elsewhere.Rafa
Had a similar issue with npm 6.9.0 and this worked for me too.Thuythuya
How to do this if package.json is auto-generated, for example, when using create-react-app?Philoprogenitive
But what if we get the issue during npm init . Error: EACCES: permission denied, open '/var/www/html/wp-content/themes/mytheme/package.jsonGristly
I
147

This command fix the issue. It worked for me:

sudo npm install -g --unsafe-perm=true --allow-root
Indiction answered 3/9, 2018 at 9:5 Comment(7)
For anyone like myself, while this command appears to have worked at the time of writing, for Node v10.10.0 I got the following error: "npm ERR! Can't install /var/www/project: Missing package name"Cheerly
The flags --unsafe-perm=true --allow-root worked for us using node v10.15.0 to install as user root an existing application where node-sass would not install. Exact command we used to get node-sass installed to local directory node_modules folder was # npm install --save-dev --unsafe-perm=true --allow-root node-sass@latestCoact
You can use root to solve the problem (though this is not recommended).Thuythuya
I was able to get it to work by using those flags so really the answer is :sudo npm install -g --unsafe-perm=true --allow-root <package-name>@<version-name>Nmr
this worked for me: sudo npm install --save -g solgraph --unsafe-perm=true --allow-rootExcellent
For those who arrive here trying to install with 'yarn' instead of 'npm', just replace it respectively.Swayback
error js ~ $ npm install -g --unsafe-perm=true --allow-root npm ERR! Cannot read properties of undefined (reading 'name') npm ERR! A complete log of this run can be found in: npm ERR! /data/data/com.termux/files/home/.npm/_logs/2022-10-09T09_45_11_327Z-debug-0.log Kriskrischer
M
81

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
Muscat answered 8/4, 2018 at 5:58 Comment(5)
worked on Mojave. Many thanks after 4-5hrs of troubleshooting, this did the trick!Cruce
4. on Catalina source ~/.zshrcNorthwest
this works for me on Ubuntu 18.04. Thanks for the helpEndmost
Worked on Mac M1 Big Sur. Thank you!Radioisotope
as said in the documentation (URL), the best way is "Reinstall npm with a node version manager". I tried this and it solved the problem.Hamate
H
43

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.

Horsetail answered 8/6, 2018 at 14:27 Comment(5)
Very unrecommended. That touches all your directories and removes root rights on any of them. If some things need to be set as root, this destroys your current configuration.Lollipop
I agree @PatrickDaSilva. This messed up my entire server..Jit
It would be safer to use an absolute path, such as chown -R myusername /home/myusername/myfolder instead of ./*. If you run the command in the answer from the root folder it will screw everything up!Hypallage
Anyway in my case it was the right solution. for some reason the Webpack output folder was owned by root so now it's owned by me again and it works. I agree you do not do this randomly, but if you look through your folders and are like WTH is this root? Then do this on that folder.Casual
@PatrickDaSilva there is no harm in changing the ownership of a users own files in their home dir to their user. In fact usually thats what you want: chown -R $USER ~/Usherette
G
34

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

sudo chmod -R 777 /yourProjectDirectoryName

run with

sudo npm install lodash
Gaga answered 28/8, 2019 at 13:47 Comment(3)
It is a jr solutionWhatever
You may not even need 777. For me the problem was just the #'s were too low. (775 fixed it.)Gobbet
"Setting 777 permissions to a file or directory means that it will be readable, writable and executable by all users and may pose a huge security risk." -linuxize.com/post/what-does-chmod-777-meanSlowly
S
20
sudo chown -R $(whoami) /usr/local/bin

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

Submissive answered 4/7, 2021 at 3:29 Comment(3)
This is work for me I changed the path to my application folder like this sudo chown -R $(whoami) /myAppPath thanksLaudatory
No offense, but this sounds like a bad idea. Your regular user account should not be the owner of /usr/local/bin. It should be owned by the superuser account.Hilversum
This is works for me. i have changed my path to $ sudo chown -R $(whoami) /usr/local/lib/node_modules/Interlocutor
A
19

Creating package.json using npm init solved my issue.

Arvell answered 12/7, 2016 at 16:24 Comment(5)
But I am not sure why package.json file is required while installing node module as package.json file is not updated or used in my case because I have not used --save or --save-dev or similar command.Arvell
this is weird. i think some thing was messed up in your npm conf and doing init reset it, anyways it should be a mystery forever as i couldn't find a single reference to a similar problem elsewhere.Rafa
Had a similar issue with npm 6.9.0 and this worked for me too.Thuythuya
How to do this if package.json is auto-generated, for example, when using create-react-app?Philoprogenitive
But what if we get the issue during npm init . Error: EACCES: permission denied, open '/var/www/html/wp-content/themes/mytheme/package.jsonGristly
O
16

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

chmod a+w <folder>

and repeat.

Ozellaozen answered 12/7, 2016 at 8:54 Comment(4)
Doesn't chown have a -r option to prevent having to use it on each and every folder in node_modules?Gassaway
@Juanjo Salvador It didn't work.It throws same error.Arvell
@Gassaway yeah, chown have a recursive option.Ozellaozen
this will cause a git issue. All the files will be notified as modified.Curvilinear
E
15

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.

Exemplify answered 1/2, 2020 at 4:34 Comment(1)
Thanks @Manohar Reddy Poreddy, after trying many solutions this worked for me.Superintend
A
13

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

Aguiar answered 28/8, 2019 at 7:16 Comment(0)
C
9

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

Congregational answered 18/11, 2019 at 1:45 Comment(1)
Worked on 20.04 also.Fatally
R
8

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.

Rafa answered 12/7, 2016 at 9:42 Comment(4)
Doing chown -R rupesh:rupesh /home/rupesh/node_modules/ and running npm install lodash again installed lodash inside ~/node_module folder.But this time it does not throw error.But it is not where I intend to install.Arvell
yes i know you should create the project in your home directory rather than Desktop. npm for some reason is installing your modules in /home/rupesh/node_modules for some reason. Any way working in your home directory should be ideal anywayRafa
I think ~/Projects/es6 is equivalent to ~/Desktop/es6 structure wise.What I am having trouble figuring out is why node_modules is not created inside es6 folder and why lodash(or whatever) module is not installed inside that. I had not faced this issue earlier but what went wrong today,that is what i want to figure out.Arvell
yup i read my previous two comment and realized the stupidity :), well i looked around and couldn't find anyone else having the same problem. Is your code able to find loadash module?.Rafa
G
7

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
Gospodin answered 27/10, 2020 at 11:17 Comment(2)
This answer seems like a better practiveElectrodeposit
This is the only solution that worked for my mac m1 despite it being 2 years old!Comstockery
S
5

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.

Standpoint answered 15/5, 2019 at 21:54 Comment(2)
Why would you allow the entire world to access this particular folder?Fears
Whatever you are hoping to accomplish, chmod 777 is wrong and dangerous. You absolutely do not want to grant write access to executable or system files to all users under any circumstances. You will want to revert to sane permissions ASAP (for your use case, probably chmod 755) and learn about the Unix permissions model before you try to use it again. If this happened on a system with Internet access, check whether an intruder could have exploited this to escalate their privileges.Gallice
A
4

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.

Asafetida answered 27/2, 2018 at 19:32 Comment(0)
N
4

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

Nolpros answered 3/12, 2019 at 6:12 Comment(0)
A
3

After trying anything, I followed this video from NPM. It solved for me smoothly! https://www.youtube.com/embed/bxvybxYFq2o

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
Astrahan answered 1/7, 2021 at 1:24 Comment(3)
Worked for me on macOS 12.1 Monterey, thanks for sharing the video and the explanation on section #4 saved me!Altogether
Too easy Alon, glad it helped.Astrahan
2023 does not work on Mac M1sComstockery
A
2

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

Atrium answered 8/8, 2017 at 11:35 Comment(1)
Worked!! On Mac moved my code folder to my root folder: HardDrive/ , and "npm install" ran flawlessly. Then I moved my code folder back to where I wanted it inside HardDrive/users/myUserName/Projects/code , ran "npm install" again, and this time, it worked.Susurration
S
2

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

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

Skimmer answered 22/10, 2019 at 18:22 Comment(0)
R
1

Remove dist folder and this solve my problem!!

Reexamine answered 17/11, 2018 at 7:51 Comment(0)
S
1

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

Satyriasis answered 27/8, 2020 at 1:57 Comment(0)
R
1

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. https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

Rokach answered 27/7, 2021 at 5:38 Comment(1)
This is not working anymore as its 2023Comstockery
A
0

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

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

Abiosis answered 21/1, 2020 at 1:38 Comment(0)
G
0

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

sudo chown -R $USER:$GROUP /usr/local/lib/node_modules
Gert answered 16/4, 2020 at 9:32 Comment(0)
B
0

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.

Buddha answered 28/8, 2020 at 6:0 Comment(0)
D
0

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

Damick answered 22/2, 2021 at 10:53 Comment(0)
B
0

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

Bastien answered 25/1, 2022 at 10:44 Comment(0)
D
0

In my case i just did the following.

  1. Create the folder if it doesn't exist. sudo mkdir ./my-folder

  2. Add permissions to the folder sudo chown -R 1001 ./my-folder

Damalus answered 1/6, 2023 at 17:1 Comment(0)
C
0

For me I was running this as root:

npm ci --unsafe-perm=true --allow-root; sudo chown -R www-data:www-data /my/project/root/node_modules; npm run build

and getting

OptimizeCssAssetsWebpackPluginError: EACCES: permission denied, open '/my/project/root/static_dev/img/ProximaNova-Regular.otf'
/my/project/root/static_dev/img/ProximaNova-Regular.otf

ProximaNova font was owned by root, but I was running npm as root. And I had the flags to allow root to run.

$ ls -l /my/project/root/static_dev/img/ProximaNova-Bold.otf
-rw-r--r-- 1 www-data www-data 63808 Jun 30 03:49 /my/project/root/static_dev/img/ProximaNova-Bold.otf

Okay, it doesn't make any sense, but none of the answers here explain why this is occurring. Change permissions on the font file, click my heals together three times, close my eyes and say "There is no place like home"

$ chown -R www-data:www-data /my/project/root

Then the npm command above worked. It would be really nice if front end tech was less cryptic.

Carilyn answered 30/6, 2023 at 3:59 Comment(0)
A
0

This error occurred because, most likely, your current user does not have proper permission on the project folder. My problem got solved when I provided proper permission to my user in the project folder.

Run this command on the project folder's terminal while you are already in your specific user. This command provide the proper

sudo chown -R $(whoami) .
Astrea answered 22/3 at 1:27 Comment(0)
F
-1

Install nvm curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh -o install_nvm.sh Install a version of node v14 using nvm install 14 Then use the node version nvm use 14 Now you can remove / delete your node_modules folder and package-lock.json file and reinstall the packages using npm install and that's it you should be okay now

Fregger answered 24/11, 2022 at 16:29 Comment(1)
Which system are you using? Mac or Linux?Comstockery

© 2022 - 2024 — McMap. All rights reserved.