当“升级升级”时,出现“权限被拒绝”错误

时间:2020-06-09 00:20:08

标签: flutter github dart permissions file-permissions

我想用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

请给我任何建议吗?

2 个答案:

答案 0 :(得分:3)

对我来说,您遇到的问题是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

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

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

答案 1 :(得分:0)

当您尝试调用某个 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

输出: enter image description here

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

sudo chown -R $USER dart-sdk

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

4) 再次检查谁是所有者

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

5) 重复您的 flutter 命令