EACCES:全局安装 NPM 包时权限被拒绝

时间:2021-03-26 17:45:14

标签: firebase npm firebase-tools

我需要为 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.

1 个答案:

答案 0 :(得分:1)

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

<块引用>

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

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

手动更改 npm 的默认目录

<块引用>

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