npm install permission denied (macOS)

2020-03-02 03:16发布

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:                 

3条回答
成全新的幸福
2楼-- · 2020-03-02 03:34

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
查看更多
仙女界的扛把子
3楼-- · 2020-03-02 03:47

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.

查看更多
神经病院院长
4楼-- · 2020-03-02 03:58

For Mac;

Run this on the Terminal >

sudo chown -R $USER /usr/local/lib/node_modules
查看更多
登录 后发表回答