npm throws error without sudo

前端 未结 30 1903
清酒与你
清酒与你 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:08

    Watch OUT!!! Watch OUT!!! Watch OUT!!!

    chown or chmod is NOT the solution, because of security-risk.

    Instead do this, do:

    First check, where npm point to, if you call:

    npm config get prefix
    

    If /usr is returned, you can do the following:

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

    This create a npm-Directory in your Home-Directory and point npm to it.

    To got this changes permanent, you have to add the export-command to your .bashrc:

    echo -e "export NPM_CONFIG_PREFIX=~/.npm-global\nexport PATH=\$PATH:~/.npm-global/bin" >> ~/.bashrc
    

提交回复
热议问题