npm install permission denied (macOS)

前端 未结 6 794
梦谈多话
梦谈多话 2021-02-07 15:08

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

相关标签:
6条回答
  • 2021-02-07 15:49

    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
    
    0 讨论(0)
  • 2021-02-07 15:53

    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

    0 讨论(0)
  • 2021-02-07 15:54

    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.

    0 讨论(0)
  • 2021-02-07 16:01

    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.

    0 讨论(0)
  • 2021-02-07 16:03

    For me it was,

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

    I tried deleting manually but didn't help

    0 讨论(0)
  • 2021-02-07 16:06

    For Mac;

    Run this on the Terminal >

    sudo chown -R $USER /usr/local/lib/node_modules
    
    0 讨论(0)
提交回复
热议问题