npm throws error without sudo

前端 未结 30 1915
清酒与你
清酒与你 2020-11-21 07:43

I just installed node and npm through the package on nodejs.org and whenever I try to search or install something with npm it throws the following error, unless I sudo the c

30条回答
  •  渐次进展
    2020-11-21 08:23

    Problem: You do not have permission to write to the directories that npm uses to store global packages and commands.

    Solution: Allow permission for npm.

    Open a terminal:

    command + spacebar then type 'terminal'

    Enter this command:

    sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
    
    • Note: this will require your password.

    This solution allows permission to ONLY the directories needed, keeping the other directories nice and safe.

提交回复
热议问题