为什么 Flutter 只能以超级用户身份运行?

Vik*_*ram 5 macos android ios dart flutter

我最近尝试在我的 Macbook Pro(2015 年初,MacOS v10.13.6)上安装Flutter框架。我将包解压到/Applications目录中,并在 bash 配置文件中创建了相应的路径。但是,当flutter doctor以默认用户身份在终端上运行命令时,我遇到以下错误。

\n\n
shlock: open(/Applications/flutter/bin/cache/shlock2538): Permission denied\nshlock: open(/Applications/flutter/bin/cache/shlock2540): Permission denied\nshlock: open(/Applications/flutter/bin/cache/shlock2542): Permission denied\nshlock: open(/Applications/flutter/bin/cache/shlock2544): Permission denied\nshlock: open(/Applications/flutter/bin/cache/shlock2546): Permission denied\nshlock: open(/Applications/flutter/bin/cache/shlock2548): Permission denied\nshlock: open(/Applications/flutter/bin/cache/shlock2550): Permission denied\n
Run Code Online (Sandbox Code Playgroud)\n\n

当我flutter doctor使用超级用户权限 ( sudo) 运行该命令时,它能够运行,并且得到以下终端输出。

\n\n
Woah! You appear to be trying to run flutter as root.\n   We strongly recommend running the flutter tool without superuser privileges.\n  /\n\nDoctor summary (to see all details, run flutter doctor -v):\n[\xe2\x9c\x93] Flutter (Channel beta, v0.5.1, on Mac OS X 10.13.6 17G65, locale en)\n[\xe2\x9c\x93] Android toolchain - develop for Android devices (Android SDK 28.0.1)\n[!] iOS toolchain - develop for iOS devices (Xcode 9.4.1)\n    \xe2\x9c\x97 CocoaPods not installed.\n        CocoaPods is used to retrieve the iOS platform side\'s plugin code that responds to your plugin usage on the Dart side.\n        Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS.\n        For more info, see https://flutter.io/platform-plugins\n      To install:\n        brew install cocoapods\n        pod setup\n[\xe2\x9c\x93] Android Studio (version 3.1)\n[!] Connected devices\n    ! No devices available\n\n! Doctor found issues in 2 categories.\n
Run Code Online (Sandbox Code Playgroud)\n\n

我更喜欢以默认用户身份运行 Flutter,而不是使用超级用户权限(即使我收到框架发出的以默认用户身份运行的警告)。

\n\n

谁能帮助我了解如何修复此错误并开始使用默认用户帐户运行 Flutter 框架?谢谢。

\n

小智 8

我尝试按照 G\xc3\xbcnter Z\xc3\xb6chbauer 的回答更改 flutter 的位置。但是,flutter 仍然需要超级用户权限。所以,我就这样直接给了他们

\n\n
sudo chown -R $USER /Users/yourUser/flutter/\n
Run Code Online (Sandbox Code Playgroud)\n\n

这对我来说效果很好。基本上,向用户授予特定文件夹的权限。

\n


Gün*_*uer 3

Flutter 在其安装目录中维护了多个文件,如 Dart 快照文件,这就是为什么/Applications默认情况下仅对 root 用户具有写入权限的 目录不是安装 Flutter 的好地方。

/Users/yourUser/flutter没有 root 权限也能正常工作。