Error npm throws error without sudo

0 votes

I just installed node and npm through the package on nodejs.org and whenever I try to search or install something with npm it throws the following error, unless I sudo the command. 

npm ERR! Error: EACCES, open '/Users/niroj/.npm/-/all/.cache.json'

npm ERR!  { [Error: EACCES, open '/Users/niroj/.npm/-/all/.cache.json']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/Users/niroj/.npm/-/all/.cache.json' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 12.2.0
npm ERR! command "node" "/usr/local/bin/npm" "search" "bower"
npm ERR! cwd /Users/niroj
npm ERR! node -v v0.10.4
npm ERR! npm -v 1.2.18
npm ERR! path /Users/niroj/.npm/-/all/.cache.json
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, open '/Users/niroj/.npm/-/all/.cache.json'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/niroj/npm-debug.log
npm ERR! not ok code 0

How to Fix this error?

Jul 8, 2020 in Node-js by kartik
• 37,530 points
336 views

1 answer to this question.

0 votes

Hello @kartik,

This looks like a permissions issue in your home directory. To reclaim ownership of the .npm directory execute:

sudo chown -R $(whoami) ~/.npm

whoami is an actual shell command. The backticks around whoami ensure that it gets executed correctly and then placed into the chown command.

you could manually specify your username as well. If your username is "niroj", the command would be 

sudo chown -R $(niroj) ~/.npm

Hope it helps!!
Thank You!!

answered Jul 8, 2020 by Niroj
• 82,820 points

Related Questions In Node-js

0 votes
1 answer

Error:npm WARN unmet dependency in nodejs

Hii @kartik, Following are the possible solution : Manually ...READ MORE

answered Jul 12, 2020 in Node-js by Niroj
• 82,820 points
1,437 views
0 votes
1 answer

How to install a private NPM module without my own registry?

Hello @kartik, In your private npm modules add "private": true to ...READ MORE

answered Jul 13, 2020 in Node-js by Niroj
• 82,820 points
596 views
0 votes
1 answer

Error:npm install won't install devDependencies

Hello @kartik, Try: npm install --only=dev If you are worried ...READ MORE

answered Jul 15, 2020 in Node-js by Niroj
• 82,820 points
3,305 views
0 votes
2 answers

Error:npm UNMET PEER DEPENDENCY warning

Finding the compatible versions of related packages ...READ MORE

answered Aug 12, 2020 in Node-js by anonymous
• 140 points
3,096 views
0 votes
1 answer

How to download and install Lavavel framework?

Hey @kartik, First you must have xampp install ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,820 points
422 views
0 votes
1 answer

Display Laravel in browser by using cmd promt?

Hello, First you need to have laravel install ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,820 points
224 views
0 votes
1 answer

How can we get started with Laravel through Xampp?

Hii, First you need to start Apache and ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,820 points
209 views
0 votes
1 answer

How to change Laravel official name to any customize name?

Hey, You just need to go Laravel folder through ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,820 points
409 views
0 votes
1 answer

Error:sudo: npm: command not found

Hello @kartik, I had the same problem; here ...READ MORE

answered Jul 15, 2020 in Node-js by Niroj
• 82,820 points
8,013 views
0 votes
1 answer

Error:npm WARN package.json: No repository field

Hello @kartik, If you are getting this from ...READ MORE

answered Jul 9, 2020 in Node-js by Niroj
• 82,820 points
2,393 views