Fix Flutter doctor failed due to permission denied on Linux

nabbisen - May 21 '21 - - Dev Community

Problem

When I tried to install Flutter 2 on Linux, running flutter doctor was required.

Running it, however, resulted in the "Permission denied" error below.

$ flutter doctor
touch: cannot touch '/opt/flutter/bin/cache/.dartignore': Permission denied
Enter fullscreen mode Exit fullscreen mode

Should I do it as root, superuser? No. It is not recommended:

$ sudo flutter doctor
   Woah! You appear to be trying to run flutter as root.
   We strongly recommend running the flutter tool without superuser privileges.
Enter fullscreen mode Exit fullscreen mode

Solution

Invite the user you use to "flutterusers" group.
Here is an Arch Linux example. Run this command:

$ sudo usermod -a -G flutterusers <your-user>
$ # alternatively:
$ #sudo gpasswd -a <your-user> flutterusers
Enter fullscreen mode Exit fullscreen mode

Log out and login again.
Then, try flutter doctor again.

$ flutter doctor
   Building flutter tool...
Enter fullscreen mode Exit fullscreen mode

Solved 🙂

Optional: Another way (less recommended)

Alternatively, it may be solved by changing /opt/flutter permission. But it is perhaps less recommended.

$ sudo chown -R <your-user>: /opt/flutter 
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .