当“颤振升级”时,我得到“权限被拒绝”错误

Posted

技术标签:

【中文标题】当“颤振升级”时,我得到“权限被拒绝”错误【英文标题】:When " flutter upgrade", I get "Permission denied" error 【发布时间】:2020-09-28 01:41:04 【问题描述】:

我想用 Flutter 构建一个 Web 应用程序。我遵循了这个指示。 https://flutter.dev/docs/get-started/web 我使用 Windows 10、适用于 Linux 的 Windows 子系统、Debian 10。

我在~/development/目录下安装了Flutter SDK,并且已经设置好了路径。

我输入这个。

flutter channel beta

并得到这个结果。

Switching to flutter channel 'beta'...
git: From https://github.com/flutter/flutter
git:    5f21edf8b..b041144f8  stable         -> origin/stable
git:  * [new branch]          CareF-macrobenchmark-typo-fix -> origin/CareF-macrobenchmark-typo-fix
git:    c0d537ad3..311ad4bde  dart_development_service -> origin/dart_development_service
git:    456d80b9d..2f7a59a8d  dev            -> origin/dev
git:    5f21edf8b..b041144f8  flutter-1.17-candidate.3 -> origin/flutter-1.17-candidate.3
git:  * [new branch]          flutter-1.19-candidate.2 -> origin/flutter-1.19-candidate.2
git:  * [new branch]          flutter-1.19-candidate.3 -> origin/flutter-1.19-candidate.3
git:  * [new branch]          flutter-1.19-candidate.4 -> origin/flutter-1.19-candidate.4
git:    eacd1c8de..746749244  master         -> origin/master
git:  * [new tag]             1.17.3         -> 1.17.3
git:  * [new tag]             1.19.0-2.0.pre -> 1.19.0-2.0.pre
git:  * [new tag]             1.19.0-3.0.pre -> 1.19.0-3.0.pre
git:  * [new tag]             1.19.0-4.0.pre -> 1.19.0-4.0.pre
git: Switched to a new branch 'beta'
git: Branch 'beta' set up to track remote branch 'beta' from 'origin'.
Successfully switched to flutter channel 'beta'.
To ensure that you're on the latest build from this channel, run 'flutter
upgrade'

接下来,我输入这个。

flutter upgrade

那么,我明白了。

Downloading Dart SDK from Flutter engine ef9215ceb2884ddf520d321bcd822d1461330876...
mv: cannot move '/home/kazu/development/flutter/bin/cache/dart-sdk' to
'/home/kazu/development/flutter/bin/cache/dart-sdk.old': Permission denied

所以,我读了这个注释。 https://flutter.dev/docs/get-started/web#set-up

The flutter upgrade command silently fails when origin points to a personal fork. 
To validate that origin points to https://github.com/flutter/flutter.git, 
run the following commands in the root directory of your local copy of the 
https://github.com/flutter/flutter repository:

然后,我输入这个。

cd ~/development/flutter/
git remote get-url origin

然后我的终端返回了这个。

https://github.com/flutter/flutter.git

所以,我又试了一次。

flutter upgrade

我得到了同样的结果。

Downloading Dart SDK from Flutter engine ef9215ceb2884ddf520d321bcd822d1461330876...
mv: cannot move '/home/kazu/development/flutter/bin/cache/dart-sdk' to
'/home/kazu/development/flutter/bin/cache/dart-sdk.old': Permission denied

接下来,我试了sudo

sudo flutter upgrade

然后我得到了这个。

sudo: flutter: command not found

你能给我一些建议吗?

【问题讨论】:

【参考方案1】:

对我来说,您遇到的问题是当前用户在dart-sdk 文件夹中没有权限。您需要重新检查权限或dart-sdk文件夹。

示例 运行ls -la查看详情

drwxr-xr-x 10 user-xxx staff 320 6 Jun 10:18 dart-sdk

如果不是当前用户,使用sudo chown 更改dart-sdk 文件夹的所有者。

再次尝试flutter upgrade

更新 解决方案:(参考:github.com/flutter/flutter/issues/17898)

手动将 dart-sdk 重命名为其他名称可以解决问题。 或者在flutter升级之前运行这个命令git clean -xffd git pull flutter doctor

【讨论】:

非常感谢您的回答。我检查了ls -la,这就是结果。 ``` drwxr-xr-x 1 kazu kazu 4096 May 29 06:32 dart-sdk``` 当前用户是kazu,所以我还有一个问题。 嗨@KazuakiSuzuki,我在这里找到了您遇到的问题:解决方案:手动将 dart-sdk 重命名为其他名称 解决了问题。或者在flutter升级之前运行这个命令 git clean -xffd git pull flutter doctor [链接]github.com/flutter/flutter/issues/17898。我希望它有所帮助。 非常感谢您的建议。您的解决方案完美运行。我试过git clean -xffd git pull flutter doctor before flutter upgrade 没有和我一起工作【参考方案2】:

当你试图调用一些flutter 命令并有这样的输出时:

Downloading Dart SDK from Flutter engine 40441def692f444660a11e20fac37af9050245ab...
mv: rename /Library/Flutter/bin/cache/dart-sdk
to /Library/Flutter/bin/cache/dart-sdk.old: Permission denied

这意味着您没有足够的权限或文件属于另一个用户。

怎么办?

1) 使用此文件转到提供的目录。

cd /Library/Flutter/bin/cache/

2) 检查谁是所有者 通过列出所有文件:

ls -l

输出:

3) 将此文件的所有者更改为您

sudo chown -R $USER dart-sdk

提供密码(sudo 需要)并点击Enter

4) 再次检查谁是所有者

应为当前用户设置文件所有者

5) 重复您的 flutter 命令

【讨论】:

以上是关于当“颤振升级”时,我得到“权限被拒绝”错误的主要内容,如果未能解决你的问题,请参考以下文章

使用 rust 二进制文件运行 docker 映像时出现权限被拒绝错误

上传文件时Django的权限被拒绝错误

写入我要提取的文件时,Git 给了我“权限被拒绝”错误

无法设置火花笔记本得到没有这样的命令错误和权限被拒绝错误

当 CGI 尝试实例化 InternetExplorer.Application 时,IIS 权限被拒绝 70 错误

“go.tools”的权限被拒绝错误