Error updating node packages – “npm ERR! Error: EPERM: operation not permitted”

This morning I tried to update my node packages using npm install -g npm and I got the error: npm ERR! Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_modules\.staging'

 

I am running Windows 7 Professional and node version 4.6.1

Full Error message:


`-- npm@4.6.1


npm ERR! path C:\Program Files\nodejs\node_modules\.staging
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall mkdir
npm ERR! Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_modules\.staging'
npm ERR! { Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_modules\.staging'
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'mkdir',
npm ERR! path: 'C:\\Program Files\\nodejs\\node_modules\\.staging' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\ndevre\AppData\Roaming\npm-cache\_logs\2017-05-19T14_59_37_000Z-debug.log

 

 

Solution

The simple solution to this is, run your command prompt as administrator. i.e.

  • Click on start
  • Click on Accessories
  • Right click on Command
  • Click on Run as Administrator
  • Run npm cache clear
  • Then run the npm install -g npm command again

You should now be able to update your node packages.