参考:https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
修改 npm 默认目录:
cd ~
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
创建或修改~/.profile:
sudo nano ~/.profile
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
再运行就好了。