On npm install: Unhandled rejection Error: EACCES: permission denied

后端 未结 16 891
抹茶落季
抹茶落季 2020-12-02 03:51

I have managed to corrupt my npm install, and whenever I try to install packages using npm install, I receive error messages along these lines:

16条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 04:02

    This happens if the first time you run NPM it's with sudo, for example when trying to do an npm install -g.

    The cache folders need to be owned by the current user, not root.

    sudo chown -R $USER:$GROUP ~/.npm
    sudo chown -R $USER:$GROUP ~/.config
    

    This will give ownership to the above folders when running with normal user permissions (not as sudo).

    It's also worth noting that you shouldn't be installing global packages using SUDO. If you do run into issues with permissions, it's worth changing your global directory. The docs recommend:

    mkdir ~/.npm-global

    npm config set prefix '~/.npm-global'

    Then updating your PATH in wherever you define that (~/.profile etc.)

    export PATH=~/.npm-global/bin:$PATH

    You'll then need to make sure the PATH env variable is set (restarting terminal or using the source command)

    https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

提交回复
热议问题