user9252255
user9252255

Reputation:

npm install permission denied (macOS)

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

Upvotes: 68

Views: 172311

Answers (21)

Caleb Olojo
Caleb Olojo

Reputation: 21

Run this command -

sudo chown -R 501:20 "/Users/<your-mac-username>/.npm"

Upvotes: 0

eliprodigy
eliprodigy

Reputation: 598

sudo chown -R whoami ~/.npm

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

Upvotes: 0

Vidya B
Vidya B

Reputation: 1

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

Upvotes: 0

Giasin
Giasin

Reputation: 1

for me:

sudo chown -R 501:20 "/Users/giasin/.npm"

Upvotes: -1

MAUROEPCE
MAUROEPCE

Reputation: 21

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

Upvotes: 1

theamrll
theamrll

Reputation: 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.

Upvotes: -1

Japes
Japes

Reputation: 433

For Macs running Big Sur or Monterey:

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

Upvotes: 5

Mapu456
Mapu456

Reputation: 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

Upvotes: -1

sylvain s
sylvain s

Reputation: 384

Just do :

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

it will ask sudo password and you are good to go

Upvotes: 0

john foreign PH
john foreign PH

Reputation: 23

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

Upvotes: 0

Sudhir Gaurav
Sudhir Gaurav

Reputation: 107

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

Upvotes: 1

Brook
Brook

Reputation: 159

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

Upvotes: 1

Meowsleydale
Meowsleydale

Reputation: 497

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!

Upvotes: 34

abdullah gharbain
abdullah gharbain

Reputation: 185

I did this for nodemon and it work

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

then install the packages that you need

Upvotes: 3

hokage_sama
hokage_sama

Reputation: 1

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

Upvotes: 0

Shashikala
Shashikala

Reputation: 411

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.

Upvotes: 41

Sigex
Sigex

Reputation: 2949

For me it was,

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

I tried deleting manually but didn't help

Upvotes: 8

Joseph DeWeese
Joseph DeWeese

Reputation: 31

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.

Upvotes: 1

Christian Speegle
Christian Speegle

Reputation: 41

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.

Upvotes: 1

Yunus ER
Yunus ER

Reputation: 2189

For Mac;

Run this on the Terminal >

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

Upvotes: 171

dcd018
dcd018

Reputation: 771

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

Upvotes: 28

Related Questions