代码之家  ›  专栏  ›  技术社区  ›  liamhp

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

  •  0
  • liamhp  · 技术社区  · 11 月前

    正如所描述的,我正在制作一个脚本来自动清理我的构建并重新安装我的依赖项,结果意外地运行了 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 pub get 没有超级用户权限

    例如之后 颤振清洁 :

    Flutter failed to delete a directory at "/Users/liamhp/Documents/<my-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.
    

    扑腾酒吧

    Generating synthetic localizations package failed with 1 error:
    
    Error: Flutter failed to write to a file at "/Users/liamhp/Documents/<my-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/<my app>/.dart_tool/flutter_gen/gen_l10n/app_localizations_en.dart
    

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

    1 回复  |  直到 11 月前
        1
  •  1
  •   Emilio Urriola    11 月前

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