56

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 gulp-uglifyjs@0.6.2: Since gulp-sourcemaps now works, use gulp-uglify instead
npm WARN deprecated babel-preset-es2015@6.24.1:   Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update! 
npm WARN deprecated browserslist@1.7.7: 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
  • 1
    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. – Awshaf Ishtiaque Oct 25 '22 at 22:52

17 Answers17

154

For Mac;

Run this on the Terminal >

sudo chown -R $USER /usr/local/lib/node_modules
Yunus ER
  • 1,999
  • 2
  • 9
  • 14
30

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!

Meowsleydale
  • 439
  • 5
  • 15
27

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.

Ramil Aliyev 007
  • 4,437
  • 2
  • 31
  • 47
Shashikala
  • 271
  • 3
  • 2
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
dcd018
  • 711
  • 5
  • 13
7

For me it was,

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

I tried deleting manually but didn't help

Sigex
  • 2,834
  • 2
  • 24
  • 25
2

I did this for nodemon and it work

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

then install the packages that you need

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.

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.

Hoppo
  • 1,130
  • 1
  • 13
  • 32
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
Brook
  • 109
  • 1
  • 7
1

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

Sudhir Gaurav
  • 107
  • 1
  • 4
1

For Macs running Big Sur or Monterey:

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

Japes
  • 393
  • 5
  • 11
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

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
MAUROEPCE
  • 21
  • 1
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
Shayan Shafiq
  • 1,447
  • 5
  • 18
  • 25
0

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

0

Just do :

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

it will ask sudo password and you are good to go

sylvain s
  • 324
  • 4
  • 11
0

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

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

theamrll
  • 1
  • 1