npm install permission denied (macOS)
Asked Answered
L

20

65

To install a Bootstrap theme I want to run npm install. However I always receive a permission denied error.

I already tried nvm and then switched with nvm use 10.9.0 to run npm install.

I also tried sudo chown -R $(whoami) ~/.npmand sudo chown -R $USER /usr/local/lib/node_modules. Neither solved it and now I am bit out of ideas how I can continue. I use macOS High Sierra.

Marcs-MBP-3:masterclass Marc$ npm install
npm WARN deprecated [email protected]: Since gulp-sourcemaps now works, use gulp-uglify instead
npm WARN deprecated [email protected]: πŸ™Œ  Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update! 
npm WARN deprecated [email protected]: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN checkPermissions Missing write access to /Users/Marc/Desktop/Dev/masterclass/node_modules
npm ERR! path /Users/Marc/Desktop/Dev/masterclass/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/Users/Marc/Desktop/Dev/masterclass/node_modules'
npm ERR!  { [Error: EACCES: permission denied, access '/Users/Marc/Desktop/Dev/masterclass/node_modules']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/Users/Marc/Desktop/Dev/masterclass/node_modules\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/Users/Marc/Desktop/Dev/masterclass/node_modules' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/Marc/.npm/_logs/2018-08-22T12_46_51_786Z-debug.log
Lippe answered 22/8, 2018 at 12:52 Comment(3)
The solutions here are all "how"s to solve this, but none of them answers as to "why" this error is happening, does anyone know?? I encountered this sort of permission denied issue when trying to install some other library from github. – Rinker
How did you install node on your machine? which node may give more information. – Lamarckism
github.com/angular/angular-cli/issues/… This is the only working I found. The reinstalling of Node won't help. Also after doing this you should also change the permission of your whole programming directory sudo chown -R user_name Developer/ – Achromatic
P
26

Check permissions of your project root with ls -l /Users/Marc/Desktop/Dev/masterclass/. If the owner is not $USER, delete your node_modules directory, try changing the owner of that directory instead and run npm install again.

cd /Users/Marc/Desktop/Dev
rm -rf ./masterclass/node_mdoules/
chown -R $USER ./masterclass/
cd masterclass    
npm install
Pulsar answered 22/8, 2018 at 14:20 Comment(0)
O
164

For Mac;

Run this on the Terminal >

sudo chown -R $USER /usr/local/lib/node_modules
Outfit answered 3/9, 2019 at 18:52 Comment(11)
Can confirm, ran into this issue on Mac OS Catalina and this solved the issue – Flexuous
This corrects the issue on MacOS High Sierra as well. – Electrode
I also tried this today, and it worked for me, using Mac OS Catalina πŸ„πŸ½β€β™‚οΈπŸš€ – Nereus
On Big Sur, sudo chown -R $USER /usr/local/bin – Chrysotile
This fixed my problem in Mac – Pharynx
Works on Mac OS monterey as well – Histidine
Didn't work for me. I'm using macOS Monterey v12.5 – Lenz
Workd for me on monterey 12.6 – Kaolack
Months without updating firebase-tools and this command fixed it, thanks, working on MAC OS ventura – Mccauley
Works on Ventura 13.1 – Pinkie
This did not work for me on macOS Sonoma 14.2.1. I still get the same error. – Exportation
E
37

KIndly run the below commands:

  1. To check the location of the package:

    npm config get prefix

  2. Then run this :

    sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

  3. Enter the password and run installation commands

It worked for me.

Eye answered 21/2, 2021 at 11:40 Comment(4)
Correct solution for my case. – Skilling
Fixed the issue for me, thanks – Gopherwood
can confirm this worked for me on Ventura. – Reduced
after uploading Big Sur had a zillion problems....the above 2 commands allowed me to see my React App after staring at a blank screen for 48 hours...kudos – Paolapaolina
M
33

I tried everything in this thread with no luck on Big Sur, but then I tried this:

sudo npm install -g yarn

And it worked!

Monnet answered 25/9, 2021 at 0:35 Comment(2)
After a day tried, i solved my issue. thanks @Monnet – Sneakbox
This worked for me on Sonoma with gulp-cli – Lotic
P
26

Check permissions of your project root with ls -l /Users/Marc/Desktop/Dev/masterclass/. If the owner is not $USER, delete your node_modules directory, try changing the owner of that directory instead and run npm install again.

cd /Users/Marc/Desktop/Dev
rm -rf ./masterclass/node_mdoules/
chown -R $USER ./masterclass/
cd masterclass    
npm install
Pulsar answered 22/8, 2018 at 14:20 Comment(0)
C
7

For me it was,

npm cache clean --force
rm -rf node_modules
npm install

I tried deleting manually but didn't help

Commeasure answered 23/7, 2020 at 8:3 Comment(0)
F
5

For Macs running Big Sur or Monterey:

sudo chown -R $USER /usr/local/bin

Fabyola answered 13/7, 2022 at 6:11 Comment(1)
Thank you this fixed my issue - except my path was "usr/local/lib". – Skelton
S
3

I did this for nodemon and it work

sudo chown -R $USER /usr/local/lib/node_modules

then install the packages that you need

Spawn answered 14/7, 2021 at 20:51 Comment(0)
G
1

I was having a similar issue, but the accepted answer did not work for me, so I will post my solution in case anyone else comes along needing it.

I was running npm install in a project cloned from GitHub and during the clone, for whatever reason the write permission was not actually set on the project directory. To check if this is your problem, pull up Terminal and enter the following:

cd path/to/project/parent/directory
ls -l

If the directory has user write access, the output will include a w in the first group of permissions:

drwxr-xr-x  15 user  staff  480 Sep 10 12:21 project-name

This assumes that you're trying to access a project in the home directory structure of the current user. To make sure that the current user owns the project directory, follow the instructions in the accepted answer.

Guilder answered 10/9, 2019 at 17:24 Comment(0)
H
1

I entered the following:

cd /Users/Marc/Desktop/Dev
rm -rf ./masterclass/node_mdoules/
chown -R $USER ./masterclass/
cd masterclass    
npm install

once this was completed the results indicated warnings and one notice instead of previous result of no permission and error.

I then entered the following:

% sudo npm install --global firebase-tools

my result was success upon completion of the last terminal entry.

Harlequinade answered 11/7, 2020 at 15:35 Comment(1)
awesome, I had the firebase-tools installation problem as well – Shum
I
1

I have same problem because i install it from pkg, and i solve this problem use below step:

1. sudo rm -rf  /usr/local/lib/node_modules/npm/
2. brew doctor
3. brew cleanup --prune-prefix ( or sudo rm -f /usr/local/include/node)
4. brew install node
Iterative answered 28/12, 2021 at 11:51 Comment(0)
H
1

i use this command : sudo npm install -g @angular/cli Gave password and worked for mw. Took 10 secs to install angular

Heartache answered 17/1, 2022 at 13:0 Comment(0)
E
1

Ok my problem was that I thought I was installing on the path:

/Users/mauro/Documents/dev/react

Where my project was setup, but instead I was doing it on:

Users/mauro/Documents/dev/

One path higher and that is why it did not perform the installation in my case.

I simply did: cd react and voila I was able to install without problem

Explant answered 3/2, 2023 at 15:24 Comment(0)
H
0

NPM_CONFIG_PREFIX=~/.npm-global

Copy this line into ur terminal, then hit enter. Then install the necessary packages you need WITHOUT the term "sudo" in front of npm.

i.e.,

npm install -g jshint
Haemoid answered 5/6, 2020 at 12:29 Comment(0)
H
0

the only thing that work on me sudo npm i -g clasp --unsafe-perm

Hyposthenia answered 19/1, 2022 at 13:52 Comment(0)
S
0

Just do :

sudo npm install -g @sanity/cli && sanity init

it will ask sudo password and you are good to go

Shumpert answered 28/2, 2022 at 10:45 Comment(0)
V
0

Run on macOS Terminal:

sudo chown -R $USER /usr/local/bin 

then provide your password

sudo npm install -g yarn

to verify whether yarn has installed or not [enter image description here][1] sudo npm install -g yarn

https://i.sstatic.net/oTXKDXBA.png

Viscous answered 11/5 at 14:30 Comment(0)
C
0

sudo chown -R whoami ~/.npm

sudo chown -R whoami /usr/local/lib/node_modules

Caloyer answered 11/6 at 10:21 Comment(0)
G
-1

That is because you dont have the "node modules". You can install with this code:

npm install -g node-modules

then, create your react app with npm init react-app my-app

Githens answered 2/3, 2022 at 4:19 Comment(0)
B
-1

Run on macOS Terminal:

sudo chown -R $USER /usr/local/bin

It will ask for the password then you're good to go!

Hope this helps.

Basinger answered 18/11, 2022 at 3:21 Comment(0)
S
-1

for me:

sudo chown -R 501:20 "/Users/giasin/.npm"
Simplicity answered 18/2 at 12:14 Comment(1)
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review – Lamarckism

© 2022 - 2024 β€” McMap. All rights reserved.