Fix: Flutter doctor が permission denied で失敗 (Linux)

目次

問題 問題

Flutter (新しいタブで開きます) 2 を Linux (新しいタブで開きます) にインストールした時のことです。flutter doctor の実行が必要 (新しいタブで開きます)でした。

しかしながら実行すると、以下のような “Permission denied” エラーになりました。

console
$ flutter doctor
touch: cannot touch '/opt/flutter/bin/cache/.dartignore': Permission denied

root すなわちスーパーユーザーで実行することが必要なのでしょうか ? いいえ。それは推奨されません:

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

Solution Solution

使っているユーザーを “flutterusers” グループに加えてあげましょう。 Arch Linux (新しいタブで開きます) での実行例です。こちらのコマンドを実行します:

console
$ sudo usermod -a -G flutterusers <your-user>
$ # alternatively:
$ #sudo gpasswd -a <your-user> flutterusers

ログアウトして、ログインします。 ふたたび flutter doctor を実行しましょう。

console
$ flutter doctor
   Building flutter tool...

成功です 🙂

補足: 別の方法 (非推奨) 補足: 別の方法 (非推奨)

違う方法もあります。/opt/flutter のパーミッションを変更することでも解決できるかもしれません。しかし上記の方法の方が推奨されるでしょう。

console
$ sudo chown -R <your-user>: /opt/flutter 

「モバイルアプリを作る」の記事をもっと

Scqr [secureal]

Scqr [secureal]: レフレード株式会社 (新しいタブで開きます)のエンジニアリング部門

ご意見・ご感想をお寄せください。