在mac系统中,全局安装npm模块时,出现类似下面的报错
gyp WARN EACCES current user ("nobody") does not have permission to access the dev dir "/root/.cache/node-gyp/14.18.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/@tencent/xdc-cli/node_modules/@tencent/svrkit-core/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@tencent/xdc-cli/node_modules/@tencent/svrkit-core/.node-gyp'
gyp ERR! System Linux 5.4.241-1-tlinux4-0017.1
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/@tencent/xdc-cli/node_modules/@tencent/svrkit-core
gyp ERR! node -v v14.18.0
gyp ERR! node-gyp -v v5.1.0
尝试切换命令行身份 sudo -s
或者在安装命令行前面添加sudo依然无效。
出现这个问题的根本原因是因为当前安装的npm包有其他的读写系统文件的操作,但是这些操作并不是以root
身份执行的,所以就会出现权限不够的问题。
针对这个问题,npm官方已经给出了解决方案,使用下面的命令把npm user的权限设为root即可:
npm -g config set user root
评论 (0)