首页 > 解决方案 > EACCES:全局安装 NPM 包时权限被拒绝

问题描述

我需要为 firebase 托管安装 firebase 工具。所以我查看了文档并运行了命令sudo npm install -g firebase-tools,但这出现在我的终端中。

npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated xmldom@0.1.31: Deprecated due to CVE-2021-21366 resolved in 0.5.0
npm WARN deprecated har-validator@5.1.5: this library is no longer supported /usr/local/bin/firebase -> /usr/local/lib/node_modules/firebase-tools/lib/bin/firebase.js  

npm ERR! code EACCES
npm ERR! syscall /usr/local/lib
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, acces '/usr/local/lib'
npm ERR! {[Error: EACCES: permission denied, acces '/usr/local/lib']
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, acces \'/usr/local/lib\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command as root/Administrator.

标签: firebasenpmfirebase-tools

解决方案


此问题与权限有关,可以通过安装节点版本管理器来解决。

如果您在尝试全局安装软件包时看到EACCES 错误,您可以:

使用节点版本管理器重新安装 npm(推荐),

或者

手动更改 npm 的默认目录

这是避免权限问题的最佳方法。要使用节点版本管理器重新安装 npm,请按照“下载和安装 Node.js 和 npm ”中的步骤操作。在安装节点版本管理器之前,您无需删除当前版本的 npm 或 Node.js。


推荐阅读