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,510 points
883 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,880 points

Related Questions In Node-js

0 votes
0 answers

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

I've taken some code and put it in ...READ MORE

Jul 13, 2020 in Node-js by kartik
• 37,510 points
1,368 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,880 points
6,812 views
0 votes
2 answers

Error:npm UNMET PEER DEPENDENCY warning

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

answered Aug 13, 2020 in Node-js by anonymous
• 140 points
13,967 views
0 votes
1 answer

Error:nvm is not compatible with the npm config "prefix" option:

Hello @kartik, After installing nvm using brew, create ~/.nvm directory: $ ...READ MORE

answered Jul 15, 2020 in Node-js by Niroj
• 82,880 points
4,206 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,880 points
1,108 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,880 points
964 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,880 points
769 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,880 points
2,638 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,880 points
11,979 views
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,880 points
5,706 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP