在使用npm全局安装时权限不足问题
问题描述
执行npm install hexo-cli -g时报错
问题解决
参考官网docs.npmjs.com/resolving-e…
选择使用node version manager重装npm的方案
1. 卸载node/npm
之前使用安装包安装,直接傻瓜式删除各种相关文件
- Delete
nodeand/ornode_modulesfrom/usr/local/lib - Delete
nodeand/ornode_modulesfrom/usr/local/include - Delete
node,node-debug, andnode-gypfrom/usr/local/bin - Delete
.npmrcfrom your home directory (these are your npm settings, don't delete this if you plan on re-installing Node right away) - Delete
.npmfrom your home directory - Delete
.node-gypfrom your home directory - Delete
.node_repl_historyfrom your home directory - Delete
node*from/usr/local/share/man/man1/ - Delete
npm*from/usr/local/share/man/man1/ - Delete
node.dfrom/usr/local/lib/dtrace/ - Delete
nodefrom/opt/local/bin/ - Delete
nodefrom/opt/local/include/ - Delete
node_modulesfrom/opt/local/lib/ - Delete
nodefrom/usr/local/share/doc/ - Delete
node.stpfrom/usr/local/share/systemtap/tapset/
2. nvm安装
- github.com/nvm-sh/nvm/…
- 下载install.sh,终端运行
sh install.sh -
nvm -v 0.39.2
3. 安装node/npm
nvm allows you to quickly install and use different versions of node via the command line.
$ nvm use 16
Now using node v16.9.1 (npm v7.21.1)
$ node -v
v16.9.1
$ nvm use 14
Now using node v14.18.0 (npm v6.14.15)
$ node -v
v14.18.0
$ nvm install 12
Now using node v12.22.6 (npm v6.14.5)
$ node -v
v12.22.6