Flutter CLI,以 root 用户身份运行干净,现在我无法在没有 sudo 的情况下运行它

问题描述 投票:0回答:1

与描述的一样,我正在制作一个脚本来自动清理我的构建并全新安装我的依赖项,并意外地以 root 用户身份运行

flutter clean
。我没有意识到这会是一个问题,但 flutter 在继续之前给出了以下警告

Woah! You appear to be trying to run flutter as root.
   We strongly recommend running the flutter tool without superuser privileges.

之后,如果没有超级用户权限,我现在无法运行

flutter clean
flutter pub get

例如

flutter clean
之后:

Flutter failed to delete a directory at "/Users/liamhp/Documents/etch-app/.dart_tool".
Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.

flutter pub get

Generating synthetic localizations package failed with 1 error:

Error: Flutter failed to write to a file at "/Users/liamhp/Documents/etch-app/.dart_tool/flutter_gen/gen_l10n/app_localizations_en.dart".
Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.
Try running:
  sudo chown -R $(whoami) /Users/liamhp/Documents/etch-app/.dart_tool/flutter_gen/gen_l10n/app_localizations_en.dart

当我以 root 身份运行命令时,它似乎仍然有效,但我通常希望避免这样做。这里发生了什么以及我该如何撤消它?我已经尝试卸载并重新安装 flutter

flutter macos permissions sudo
1个回答
0
投票

这似乎与项目中文件和目录的所有权有关。当您以 root 身份运行命令时,它很可能会创建一些不允许其他用户修改的文件。您应该尝试运行错误消息中的 chown 命令,或者尝试删除任何生成的文件并在没有 root 的情况下重建。如果您的代码在 git 或类似的东西上,只需删除您的代码并再次克隆它即可。

© www.soinside.com 2019 - 2024. All rights reserved.