208

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 ?

Lahar Shah
  • 7,032
  • 4
  • 31
  • 39
  • 60
    Running `npm cache clean --force` solved the issue for me. – Nuhman Dec 06 '17 at 08:50
  • 4
    Running npm cache clean --force for two times worked for me. – VIshal Jain Jul 09 '19 at 10:17
  • 1
    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 Jan 22 '21 at 17:08
  • 1
    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 --force --global`. I also added `C:\Program Files\nodejs\node_modules` to my system `PATH` environment variable. – Henke Jan 23 '21 at 16:00
  • 1
    Screen-dump: https://i.imgur.com/VLFS7lG.png. But it might be a good idea to try https://stackoverflow.com/a/44014485 first. – Henke Jan 23 '21 at 16:54
  • I'd tried all these answers and none worked. Later, I installed a [Linux sub-system (WSL) in windows](https://learn.microsoft.com/en-us/windows/wsl/install-win10), and I never faced this issue again. – Dhamo Jun 08 '21 at 11:22
  • Try running the cmd as administrator – Raja Rama Mohan Thavalam Oct 05 '22 at 08:03
  • In my case, I had it working previously, and at some point when switching projects, it somehow gave me this error. I tried clearing the cache and followed some introduced fixes below, but none worked. I restarted my PC and it works like a charm. Sometimes because we are now too technical and experienced we manage to overlook the most basic fix there is. :) – Chaprel John Villegas Mar 09 '23 at 01:49

47 Answers47

178

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.

Mathias Lykkegaard Lorenzen
  • 15,031
  • 23
  • 100
  • 187
Lahar Shah
  • 7,032
  • 4
  • 31
  • 39
75

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.

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
RatneZ
  • 1,078
  • 9
  • 9
  • 2
    Add some explanation with answer for how this answer help OP in fixing current issue – ρяσѕρєя K Jun 20 '16 at 06:00
  • 2
    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. – atomic77 Mar 23 '18 at 21:07
  • 2
    this will not work with a company laptop where you are not the system admin. – schlingel Jan 17 '19 at 11:56
  • In our case we have full control but folder was hidden. If you have already full control then check hidden option of the folder. – Blast May 03 '21 at 08:21
  • This answer worked for me, I gave the **Full Control** permissions to **Users** from the Security tab of the folder properties – Aswin Barath Oct 07 '21 at 04:23
  • The equivalent to this on a build server would be `attrib -R "C:\...\wwwroot\*.*" /S /D` (TFS makes everything Read-Only when checked out). – Louis Somers Nov 26 '21 at 12:15
  • Works for me, thanks. I'm confused why D:\nodejs\node cache(this folder is created by me) is default not write permission, so i run 'npm install express -g' it shows error: ERROR EPERM mkdir operation not permitted. – Smiles Aug 22 '22 at 06:56
  • Worked like a charm! – JuBaer AD Sep 18 '22 at 09:54
53

Sometimes, all that's required is to stop the dev server before installing/updating packages.

Ezra Obiwale
  • 1,756
  • 1
  • 12
  • 15
38

Restarting VsCode solved it for me!

Legends
  • 21,202
  • 16
  • 97
  • 123
27

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 npm@5.3 -g

Try update the version in another moment.

Leonardo Oliveira
  • 1,349
  • 1
  • 12
  • 14
21

I use Windows 10. I started the CMD as administrator, and it solved the problem.

Find CMD, right click, and click open as administrator.

nicovank
  • 3,157
  • 1
  • 21
  • 42
DIANGELISJ
  • 727
  • 6
  • 4
  • @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. – Clonkex Jul 20 '20 at 00:59
  • 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. – Etienne Gautier Jul 20 '20 at 16:25
  • @EtienneGautier Ah fair enough. – Clonkex Jul 20 '20 at 22:58
20

I had an outdated version of npm. I ran a series of commands to resolve this issue:

npm cache clean --force

Then:

npm install -g npm@latest --force

Then (once again):

npm cache clean --force

And finally was able to run this (installing Angular project) without the errors I was seeing regarding EPERM:

ng new myProject
LatentDenis
  • 2,839
  • 12
  • 48
  • 99
  • As of npm@5 it is recommended if you use ```npm cache verify``` AKA a self healing mechanism ; which will ensure everything is consistent – ben Jun 12 '21 at 13:31
  • Thanks brother, it works for me. I was trying to create a react application. – Rahul Sarma Jul 02 '23 at 11:26
15

In my case, I was facing this error because my directory and its file were opened in my editor (VS code) while I was running npm install. I solved the issue by closing my editor and running npm install through the command line.

Shashank Rawat
  • 1,371
  • 13
  • 15
13

I had the same problem when I tried to install the npm package AVA. The solution for me was to delete the node_modules folder and force-clean the npm cache:

rm -rf node_modules
npm cache clean --force

I could then install the npm package without a problem.

Liran H
  • 9,143
  • 7
  • 39
  • 52
  • 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. – Ashokan Sivapragasam Mar 07 '19 at 10:38
11

I had the same problem, after updating npm. Solved it by re-installing latest npm again with:

npm i -g npm

but this time with cmd running in administrating mode.

i did all this because i suspected there was an issue with the update, mostly some missing files.

Web Steps
  • 334
  • 2
  • 11
8

for me it was an issue of altering existing folders in node_module, so i nuked the whole folder and run npm install again. it works with no errors after that

Sonic Soul
  • 23,855
  • 37
  • 130
  • 196
7

The Problem I faced (In Windows Computer)

When I was trying to install a couple of npm packages I got the following error:

npm - EPERM: operation not permitted - while npm was trying to rename a file

Here's my debug snippet for reference, if you've faced the similar problem:

The Problem I faced

After carefully checking out the answers from other users, I have created a detailed answer for the community

My Solution for the problem

Follow the mentioned steps

  1. Right-click on the project folder
  2. Go to properties -> Security Tab
  3. Select Users -> Edit
  4. In the Permission for Users section, Full control -> Give a check mark in Allow -> OK
  5. Wait for Windows security to apply the new security rules
  6. Click OK

Visualization of the steps

Change Security rules

If you follow these steps and try to install npm packages again it will work properly.

Note: It's a best practice to close and open up the command line again to experience the changes

Aswin Barath
  • 889
  • 9
  • 13
5

Just run cmd as admin. delete old node_modules folder and run npm install again.

Rahul Khunt
  • 643
  • 5
  • 6
  • 3
    npm install should work without starting CMD as admin. It is not working on normal cmd(non admin) is also an issue. – Lahar Shah Dec 11 '17 at 05:52
4

Happened to me since the folder/file was locked by another process. Used a tool (LockHunter) to terminate that process and it started working again (possible reason).

Hummus
  • 559
  • 1
  • 9
  • 21
4

Simplest way

Hope I am not too late for this post but recently even I too got hit by this issue. And also I had no admin rights on my laptop.

Here is the simplest way I fixed the bug.

  1. Locate the file name .npmrc (it will be in C:\Users\<user name>\.npmrc)
  2. Open it and change the path of prefix= to prefix=C:\Users\<user name>\AppData\Roaming\npm

hope it will be helpful..

Rishabh Jain
  • 169
  • 1
  • 9
4

This error is caused by different problems try the below one of them will work for you!

  • try to run npm as Administrator

  • Run cmd as administrator npm config edit (You will get notepad editor) Change Prefix variable to C:\Users\<User Name>\AppData\Roaming\npm

  • The errors went after I disabled my anti-virus (Avast)

  • Sometimes a simple cache clear like the below would fix it.

     npm cache clear
    
Ericgit
  • 6,089
  • 2
  • 42
  • 53
3

If you getting this error in an IDE's terminal/commands prompt, try delete node_modules, close IDE, and run the npm install command again. The time when IDE started but still not completed its analysis of node_modules tree is a tricky moment, when packages installation may fail because IDE still scanning node_modules contents.

Kote Isaev
  • 273
  • 4
  • 13
2

Running npm commands in Windows Powershell solved my issue.

Sai Prasad
  • 131
  • 9
  • I was working on my company laptop, on which I regularly face some or the other issues with proxy or some security thing. I tried many things mentioned here and finally did this and it worked for me. But, not sure if doing this alone will be enough. – chandraprakash-dev Aug 12 '23 at 06:22
2
npm install cross-env

Try this it worked for me.

Samsul Islam
  • 2,581
  • 2
  • 17
  • 23
Mohit Poddar
  • 171
  • 1
  • 2
2

For me the problem come from bash terminal. I change my terminal to powershell and it's ok.

Really easy to resolve

steph
  • 45
  • 1
  • 8
  • 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](/help/how-to-answer). – Community Mar 31 '22 at 10:49
  • While circumventing the problem (by using another terminal) may be useful, I would much rather understand the problem and how to actually resolve it (in any terminal). In my case, the error occurs regardless of whether its executed in Git Bash (mingw64), cmd.exe, or PowerShell. (Oddly, running as administrator caused a different error message to result, but that might be irrelevant.) – jacobq Sep 15 '22 at 20:57
1

Find this command npm cache clean as a solution to those error in quick and simple way!

Hanny Setiawan
  • 501
  • 4
  • 14
1

I updated my node version to 8.9.4 and ran the necessary install command again from administrator command prompt. It worked for me!

Rahul Sharma
  • 329
  • 1
  • 3
  • 10
1

A reboot of my laptop and then

npm install

worked for me!

Chau Nguyen
  • 894
  • 8
  • 13
1

Try npm i -g npm . NPM version 6.9 is work to me.

karlos
  • 807
  • 1
  • 8
  • 38
1

Apparently anti-virus software can also cause this error. In my case I had Windows Security's Ransomware Protection protecting my user folders which caused this error.

orrd
  • 9,469
  • 5
  • 39
  • 31
1

Windows 10,

Running the IDE (in my case IntelliJ) in administrator mode and executing npm install does resolves the problem.

If no IDE then run CMD in administrator mode and try executing npm install

Sasi Kumar M
  • 2,440
  • 1
  • 23
  • 23
1

For those trying to update config

If having trouble updating your npm config, try instead running using the -g flag. This solved the issue on Win 10 for me after trying everything else.

npm config edit -g

I am able to update the config and changes are reflected everywhere. This may be due to running npm in an organizational scope.

factorypolaris
  • 2,757
  • 12
  • 15
1

I was running create-react-app server. Simply stopped the server and everything worked just fine.

Saffer
  • 152
  • 8
1

The simpler way to solve this by entering the below command

npm config set cache C:\tmp\nodejs\npm-cache --global
Hadayat Niazi
  • 1,991
  • 3
  • 16
  • 28
1

At least I just solved my problem in this way:

  1. Search cmd
  2. Then run as administrator
  3. Then npm i -g expo-cli or npm config set prefix /usr/local

I just solved my problem.

Alamin
  • 1,878
  • 1
  • 14
  • 34
1

Try installing it globally first, using the command {npm install -g create-react-app}

And then, you can create your app using the command, {npx create-react-app }

worked for me

AL Mahmud
  • 113
  • 2
1

Just stop react server and then install the package.

This issue occurs because when react is running (with yarn start or npm start), It is using some resources.

mohammad asghari
  • 1,817
  • 1
  • 16
  • 23
1

My only solution for this issue was changing the directory of the project (using Window OS). Initially was stored to C:/. when I move to C:\Users\test\Desktop started to work.

vlatko606
  • 909
  • 1
  • 13
  • 21
0

I had the same issue, as I was using my company LAN. And I just ran cmd.exe npm and I was able to execute my other commands without any error after that.

C:\Users\586656>cmd.exe npm
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

Just sharing this, as it may help other folks who try to do this in their office LAN. Thank you.

Sibeesh Venu
  • 18,755
  • 12
  • 103
  • 140
0

Try to install npm package by running CMD as Administrator. you can headover to broad discussion on this bug at npm install throwing error EPERM.

Kiran Maniya
  • 8,453
  • 9
  • 58
  • 81
0

Same to me, My solution was close Android studio, AVD Manager, Visual Studio and reinstall. I executed this command to update my expo cli:

npm install -g expo-cli
Loitd
  • 331
  • 2
  • 3
0

For me, It was an issue with the .npmrc file. Which is present in C:\Users\myname.npmrc Somehow the content of .npmrc file got changed. I have changed the content by comparing with my colleagues laptop. So it solved.

For reference, I am adding the content of .npmrc file too

 ;;;;
 ;npm userconfig file
 ;this is a simple ini-formatted file
 ;lines that start with semi-colons are comments.
 ;read `npm help config` for help on the various options
 ;;;;

 //registry.npmjs.org/:_authToken=95632bcf-3056-4538-b57d-38426736e3a0
 scope=true
 @true:registry=https://registry.npmjs.org/

 ;;;;
 ;all options with default values
 ;;;;
 ;access=null

 ;allow-same-version=false

 ;always-auth=false

 ;also=null

 ;audit=true

 ;audit-level=low

 ;auth-type=legacy

 ;before=null

 ;bin-links=true

 ;browser=null

 ;ca=null

 ;cafile=undefined

 ;cache=C:\Users\myname\AppData\Roaming\npm-cache

 ;cache-lock-stale=60000

 ;cache-lock-retries=10

 ;cache-lock-wait=10000

 ;cache-max=null

 ;cache-min=10

 ;cert=null

 ;cidr=null

 ;color=true

 ;depth=null

 ;description=true

 ;dev=false

 ;dry-run=false

 ;editor=notepad.exe

 ;engine-strict=false

 ;force=false

 ;fetch-retries=2

 ;fetch-retry-factor=10

 ;fetch-retry-mintimeout=10000

 ;fetch-retry-maxtimeout=60000

 ;git=git

 ;git-tag-version=true

 ;commit-hooks=true

 ;global=false

 ;globalconfig=C:\Users\myname\AppData\Roaming\npm\etc\npmrc

 ;global-style=false

 ;group=0

 ;ham-it-up=false

 ;heading=npm

 ;if-present=false

 ;ignore-prepublish=false

 ;ignore-scripts=false

 ;init-module=C:\Users\myname\.npm-init.js

 ;init-author-name=

 ;init-author-email=

 ;init-author-url=

 ;init-version=1.0.0

 ;init-license=ISC

 ;json=false

 ;key=null

 ;legacy-bundling=false

 ;link=false

 ;local-address=undefined

 ;loglevel=notice

 ;logs-max=10

 ;long=false

 ;maxsockets=50

 ;message=%s

 ;metrics-registry=null

 ;node-options=null

 ;node-version=10.15.2

 ;offline=false

 ;onload-script=null

 ;only=null

 ;optional=true

 ;otp=null

 ;package-lock=true

 ;package-lock-only=false

 ;parseable=false

 ;prefer-offline=false

 ;prefer-online=false

 ;prefix=C:\Program Files\nodejs

 ;preid=

 ;production=false

 ;progress=true

 ;proxy=null

 ;https-proxy=null

 ;noproxy=null

 ;user-agent=npm/{npm-version} node/{node-version} {platform} {arch}

 ;read-only=false

 ;rebuild-bundle=true

 ;registry=https://registry.npmjs.org/

 ;rollback=true

 ;save=true

 ;save-bundle=false

 ;save-dev=false

 ;save-exact=false

 ;save-optional=false

 ;save-prefix=^

 ;save-prod=false

 ;scope=

 ;script-shell=null

 ;scripts-prepend-node-path=warn-only

 ;searchopts=

 ;searchexclude=null

 ;searchlimit=20

 ;searchstaleness=900

 ;send-metrics=false

 ;shell=C:\windows\system32\cmd.exe

 ;shrinkwrap=true

 ;sign-git-commit=false

 ;sign-git-tag=false

 ;sso-poll-frequency=500

 ;sso-type=oauth

 ;strict-ssl=true

 ;tag=latest

 ;tag-version-prefix=v

 ;timing=false

 ;tmp=C:\Users\myname\AppData\Local\Temp

 ;unicode=false

 ;unsafe-perm=true

 ;update-notifier=true

 ;usage=false

 ;user=0

 ;userconfig=C:\Users\myname\.npmrc

 ;umask=0

 ;version=false

 ;versions=false

 ;viewer=browser

 ;_exit=true

 ;globalignorefile=C:\Users\myname\AppData\Roaming\npm\etc\npmignore
Thilak Raj
  • 880
  • 3
  • 10
  • 25
0

After trying everything and nothing works. Moving my working project folder to diffrent destination worked for me.

Akhil Bisht
  • 121
  • 2
  • 8
0

Likely when you experience this issue, it is possible is a permission issue on your PC. Going to the PC properties and granting which ever account you use on your PC full control will solve it.

Again command /usr/local doesn't work on windows

Jude Obiejesi
  • 86
  • 1
  • 15
0

If cleaning the cache(npm cache clean --force) doesn't help you just delete manually the folder C:\Users\%USER_NAME%\AppData\Roaming\npm-cacheand and reinstall NodeJS

Denys Rusov
  • 560
  • 6
  • 6
0

Install create-react-app

I did not install create-react app. so I just run npm install -g create-react-app and the problèm was solved

Kamba-Bilola Ted
  • 197
  • 4
  • 12
0

Incredibly, this happens when you are building your project, e.g.

ng build myprojet

...and you are stood up inside the dist/myprojet, maybe withing the console. So you can easily close that console window or cd .. to prevent this from happening.

EliuX
  • 11,389
  • 6
  • 45
  • 40
0

I'd to update my npm using npm-windows-upgrade

Manish Paul
  • 424
  • 1
  • 8
  • 17
0

In my case, it had to do with the directory webpack was targeting to build the files. Somehow, the directory couldn´t be deleted, even if I would try to do it manually by windows explorer. So, you can either force delete through CMD or, as strange as it may sound, I closed my web browser that I was using to load the webpack compiled files and managed to get the directory deleted. Afterwards, I ran webpack again and worked. Maybe that was causing the directory dele block.

Jorge Mauricio
  • 411
  • 6
  • 18
0

I was having trouble with this issue as well. Try updating Node to the latest version and then try the operation again. It may help you.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31189140) – Ervin Szilagyi Mar 05 '22 at 18:07
0

I have faced the same problem and tried all the given solutions and none of them worked.

I got it solved after adding package.json as there was no package.json file available in the folder where I was trying to install a module and faced the same error.

Give it a try maybe it helps someone

npm init

npm init all (skip configurations)
Salman
  • 1,266
  • 5
  • 21
  • 41
0

Executing the command by specifying the version fixed it for me.

npm install --global npm@9.2.0

Unfortunately, neither did the restarting of the computer, executing npm i -g npm@latest or without @latest, executing npm cache clean/verify with or without respective --force argument, and even removing npm and node_modules folders and even providing access rights to the parent folder helped me.

Specifying the npm version worked.

knoxgon
  • 1,070
  • 2
  • 15
  • 31