npm - EPERM: operation not permitted on Windows
Solution 1
Running this command was my mistake.
npm config set prefix /usr/local
Path /usr/local
is not for windows. This command changed the prefix variable at 'C:\Program Files (x86)\Git\local'
To access and make a change to this directory I need to run my cmd as administrator.
So I did:
- Run cmd as administrator
- Run
npm config edit
(You will get notepad editor) - Change
prefix
variable toC:\Users\<User Name>\AppData\Roaming\npm
Then npm start
works in a normal console.
Solution 2
This is occurring because windows is not giving permission to the user to create a folder inside system drive. To solve this:
Right Click
The Folder > Properties > Security Tab
Click on Edit to change Permissions > Select the user and give Full Control to that user.
Solution 3
Sometimes, all that's required is to stop the dev server before installing/updating packages.
Solution 4
I solved the problem by changing windows user access for the project folder:
Here is a screenshot: http://prntscr.com/djdn0g
Solution 5
I recently had the same problem when I upgraded to the new version, the only solution was to do the downgraded
To uninstall:
npm uninstall npm -g
Install the previous version:
npm install [email protected] -g
Try update the version in another moment.
Related videos on Youtube
Lahar Shah
Updated on July 08, 2022Comments
-
Lahar Shah almost 2 years
I ran
npm config set prefix /usr/local
After running that command, When trying to run any npm commands on Windows OS I keep getting the below.
Error: EPERM: operation not permitted, mkdir 'C:\Program Files (x86)\Git\local' at Error (native)
Have deleted all files from
C:\Users\<your username>\.config\configstore\
It did not work.
Any suggestion ?
-
Nuhman over 6 yearsRunning
npm cache clean --force
solved the issue for me. -
VIshal Jain almost 5 yearsRunning npm cache clean --force for two times worked for me.
-
Henke over 3 yearsDid you run it in the
cmd.exe
"terminal" (command prompt) or from theGitBash
terminal? For me, it failed when I ran it inGitBash
but worked fine when I ran it incmd
. -
Henke over 3 yearsToday I got EPERM even in
cmd.exe
. But I ran the following command standing inC:\Program Files\nodejs
, and it seems to have worked:npm cache clean --force && npm install <package-name> --force --global
. I also addedC:\Program Files\nodejs\node_modules
to my systemPATH
environment variable. -
Henke over 3 yearsScreen-dump: i.imgur.com/VLFS7lG.png. But it might be a good idea to try stackoverflow.com/a/44014485 first.
-
Dhamo almost 3 yearsI'd tried all these answers and none worked. Later, I installed a Linux sub-system (WSL) in windows, and I never faced this issue again.
-
-
ρяσѕρєя K almost 8 yearsAdd some explanation with answer for how this answer help OP in fixing current issue
-
Leonardo Oliveira over 6 yearsExactly, I'm following this topic to know when it will be fixed.
-
Lahar Shah over 6 yearsnpm install should work without starting CMD as admin. It is not working on normal cmd(non admin) is also an issue.
-
atomic77 about 6 yearsGranting the user access to change system folders is not a good idea, especially when this can be easily fixed by changing the prefix to a folder in the user's home directory.
-
ruffin almost 6 yearsIn my case, I simply uncommented
prefix
(was;prefix...
) afternpm config edit
, and Profit. Not sure if that's A Smart Thing, but it worked. -
Dimitar Nikovski over 5 yearshow odd but true... installing [email protected] for trying out react hooks didn't work until trying this
-
schlingel over 5 yearsthis will not work with a company laptop where you are not the system admin.
-
Ashokan Sivapragasam about 5 yearsYes, I somehow was having node_modules folders in the current working directory. It was throwing that exception when I tried to run angular cli commands 'ng new..'. Deleting node_modules folders helped.
-
Rishabh Jain almost 5 yearsin my case I had no admin rights to me on the laptop so here's how I did it- stackoverflow.com/a/57249779/10603466
-
canbax over 4 yearsthis is answer is duplicate of stackoverflow.com/a/37915233/3209523
-
Ng Sek Long over 4 yearsTo add to this, if you suspect this issue is your dev server running but don't know how to stop it, just logout / restart your windows will always fix this lool
-
Unbreakable about 4 yearsJust re-running as admin fixed my issue.
-
Fahim Uddin about 4 yearsPlease first read the question clearly and understand what the problem is, then try to answer with descriptive and related format of how and why your answer can be a possible solution. Hope it helps !
-
Clonkex almost 4 years@EtienneGautier That's... simply not true at all. What's your proposed solution for modifying system files? If there's any way to do it other than with "administrator permissions" then there's something seriously wrong with the OS's security.
-
Etienne Gautier almost 4 yearsHey @Clonkex, I was assuming that the context was NPM's one (according to the question). Still my comment is not relevant, I'm deleting it. Thank you for your feedback.
-
Clonkex almost 4 years@EtienneGautier Ah fair enough.
-
Blast almost 3 yearsIn our case we have full control but folder was hidden. If you have already full control then check hidden option of the folder.
-
ben almost 3 yearsAs of npm@5 it is recommended if you use
npm cache verify
AKA a self healing mechanism ; which will ensure everything is consistent -
Aswin Barath over 2 yearsThis answer worked for me, I gave the Full Control permissions to Users from the Security tab of the folder properties
-
Louis Somers over 2 yearsThe equivalent to this on a build server would be
attrib -R "C:\...\wwwroot\*.*" /S /D
(TFS makes everything Read-Only when checked out). -
Ervin Szilagyi about 2 yearsThis does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
-
Admin about 2 yearsYour answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.