npm install: Error: EACCES: permission denied, mkdir

后端 未结 4 1961
清歌不尽
清歌不尽 2021-02-03 14:46

I attempted to do a sudo npm install -g appium on Mac OS 10.12.5.

I get this error:

info Chromedriver Install Installing Chromedri

4条回答
  •  长发绾君心
    2021-02-03 15:11

    The -g option means install globally. When packages are installed globally, EACCES permission errors can occur.

    Consider setting up npm to operate globally without elevated permissions. See Resolving Permission Errors for more information.

    Option 1

    The best way to avoid permission issues is to reinstall NodeJS and npm using a node version manager.

    1. Install nvm

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
    

    You can close and reopen the terminal ou just open another terminal and check if nvm is installed properly with this command: command -v nvm.

    2. To download and install the latest LTS release of NodeJS, run:

    nvm install --lts
    

    3. Set the newly installed NodeJS as the default environment:

    nvm alias default lts/*
    

    Option 2 (Does not apply for windows)

    Change the owner of npm's directories to the current user:

    sudo chown -R $(your_user) /usr/local/{lib/node_modules,bin,share}
    sudo chown -R $(your_user) ~/.npm ~/.npmrc
    

提交回复
热议问题