You need to enable JavaScript to run this app. Mac Big Sur安装firebase-tools出现EACCES权限错误如何解决
优惠活动
大模型
产品
解决方案
定价
更多

Mac Big Sur安装firebase-tools出现EACCES权限错误如何解决

macOS下安装firebase-tools权限错误解决方案

报错原因

  • 不加sudo执行时,当前用户没有/usr/local/lib/node_modules目录的写入权限,直接返回EACCES错误
  • 加sudo执行时,npm默认会将安装生命周期脚本的执行用户切换为nobody,该用户无权限访问编译所需的缓存目录与系统安装目录,触发re2包编译阶段的权限错误

推荐解决方案(一劳永逸,无后续权限问题)

修改npm全局包安装路径到当前用户目录,规避系统目录权限限制:

  1. 创建用户专属的npm全局安装目录
mkdir ~/.npm-global
  1. 配置npm使用该目录作为全局安装前缀
npm config set prefix '~/.npm-global'
  1. 将全局包的可执行文件路径加入系统环境变量

macOS 10.15+ 默认使用zsh,执行以下命令:

echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc
source ~/.zshrc

如果你使用bash作为默认shell,执行以下命令:

echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
  1. 无需sudo直接安装firebase-tools
npm install -g firebase-tools

可选快速解决方案

方案1:修改系统node_modules目录所属用户

sudo chown -R $USER /usr/local/lib/node_modules
npm install -g firebase-tools

方案2:临时添加unsafe-perm参数安装

让npm以root权限执行所有安装脚本,避免切换到nobody用户触发权限错误:

sudo npm install -g firebase-tools --unsafe-perm=true

内容的提问来源于stack exchange,提问作者Axil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.15 04:54:00