npm - EPERM: operation not permitted on Windows

458,957

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:

  1. Run cmd as administrator
  2. Run npm config edit (You will get notepad editor)
  3. Change prefix variable to C:\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

enter image description here

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.

Share:
458,957

Related videos on Youtube

Lahar Shah
Author by

Lahar Shah

Updated on July 08, 2022

Comments

  • Lahar Shah
    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
      Nuhman over 6 years
      Running npm cache clean --force solved the issue for me.
    • VIshal Jain
      VIshal Jain almost 5 years
      Running npm cache clean --force for two times worked for me.
    • Henke
      Henke over 3 years
      Did you run it in the cmd.exe "terminal" (command prompt) or from the GitBash terminal? For me, it failed when I ran it in GitBash but worked fine when I ran it in cmd.
    • Henke
      Henke over 3 years
      Today I got EPERM even in cmd.exe. But I ran the following command standing in C:\Program Files\nodejs, and it seems to have worked: npm cache clean --force && npm install <package-name> --force --global. I also added C:\Program Files\nodejs\node_modules to my system PATH environment variable.
    • Henke
      Henke over 3 years
      Screen-dump: i.imgur.com/VLFS7lG.png. But it might be a good idea to try stackoverflow.com/a/44014485 first.
    • Dhamo
      Dhamo almost 3 years
      I'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
    ρяσѕρєя K almost 8 years
    Add some explanation with answer for how this answer help OP in fixing current issue
  • Leonardo Oliveira
    Leonardo Oliveira over 6 years
    Exactly, I'm following this topic to know when it will be fixed.
  • Lahar Shah
    Lahar Shah over 6 years
    npm install should work without starting CMD as admin. It is not working on normal cmd(non admin) is also an issue.
  • atomic77
    atomic77 about 6 years
    Granting 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
    ruffin almost 6 years
    In my case, I simply uncommented prefix (was ;prefix...) after npm config edit, and Profit. Not sure if that's A Smart Thing, but it worked.
  • Dimitar Nikovski
    Dimitar Nikovski over 5 years
    how odd but true... installing [email protected] for trying out react hooks didn't work until trying this
  • schlingel
    schlingel over 5 years
    this will not work with a company laptop where you are not the system admin.
  • Ashokan Sivapragasam
    Ashokan Sivapragasam about 5 years
    Yes, 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
    Rishabh Jain almost 5 years
    in 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
    canbax over 4 years
    this is answer is duplicate of stackoverflow.com/a/37915233/3209523
  • Ng Sek Long
    Ng Sek Long over 4 years
    To 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
    Unbreakable about 4 years
    Just re-running as admin fixed my issue.
  • Fahim Uddin
    Fahim Uddin about 4 years
    Please 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
    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
    Etienne Gautier almost 4 years
    Hey @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
    Clonkex almost 4 years
    @EtienneGautier Ah fair enough.
  • Blast
    Blast almost 3 years
    In our case we have full control but folder was hidden. If you have already full control then check hidden option of the folder.
  • ben
    ben almost 3 years
    As 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
    Aswin Barath over 2 years
    This answer worked for me, I gave the Full Control permissions to Users from the Security tab of the folder properties
  • Louis Somers
    Louis Somers over 2 years
    The 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
    Ervin Szilagyi about 2 years
    This 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
    Admin about 2 years
    Your 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.