'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
Solution 1:[1]
For Mac;
Run this on the Terminal >
sudo chown -R $USER /usr/local/lib/node_modules
Solution 2:[2]
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!
Solution 3:[3]
KIndly run the below commands:
To check the location of the package:
npm config get prefixThen run this :
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}Enter the password and run installation commands
It worked for me.
Solution 4:[4]
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.
Solution 5:[5]
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.
Solution 6:[6]
For me it was,
npm cache clean --force
rm -rf node_modules
npm install
I tried deleting manually but didn't help
Solution 7:[7]
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
Solution 8:[8]
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
Solution 9:[9]
I did this for nodemon and it work
sudo chown -R $USER /usr/local/lib/node_modules
then install the packages that you need
Solution 10:[10]
i use this command : sudo npm install -g @angular/cli Gave password and worked for mw. Took 10 secs to install angular
Solution 11:[11]
the only thing that work on me sudo npm i -g clasp --unsafe-perm
Solution 12:[12]
Just do :
sudo npm install -g @sanity/cli && sanity init
it will ask sudo password and you are good to go
Solution 13:[13]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
