相关文章推荐
迷茫的警车  ·  java url 反转义-掘金·  1 年前    · 
淡定的红薯  ·  HttpContext.User ...·  1 年前    · 
打酱油的槟榔  ·  Getting Started | ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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) ~/.npm and 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
                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, 2022 at 22:52

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!

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

    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.

    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.

    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
    

    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

    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
    

    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

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.

  •