flutter upgrade - failed to create a directory at "/Users/.../.config/flutter". - Flutter Daemon has terminated

3,279

Solution 1

Run this command in terminal:

sudo chown mohittanwar /Users/mohittanwar/.config

That solves my problem... Note: Use your own system user name.

Solution 2

I also had the same issue, but got solved when I did the below steps.

sudo flutter downgrade

sudo flutter doctor

sudo flutter upgrade

sudo flutter doctor

I had error when the flutter upgrade was done, but got solved when I ran flutter doctor.

Share:
3,279
Moo
Author by

Moo

Updated on December 28, 2022

Comments

  • Moo
    Moo over 1 year

    after upgrading flutter on my Mac the "flutter doctor" command doesn't work because of "failed to create a directory at "/Users/Michael/.config/flutter". The flutter tool cannot access the file or directory."

    Why I get this message and why I can't debug anymore: "The Flutter Daemon has terminated. Cannot launch without an active device" ?

    Before "flutter upgrade" the "flutter doctor"-command worked (with and without sudo):

    ´´´

    flutter doctor -v
    [✓] Flutter (Channel stable, 1.22.6, on macOS 11.2.3 20D91 darwin-x64, locale de-DE)
        • Flutter version 1.22.6 at /Users/Michael/Documents/Developer/flutter
        • Framework revision 9b2d32b605 (7 weeks ago), 2021-01-22 14:36:39 -0800
        • Engine revision 2f0af37152
        • Dart version 2.10.5
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
        • Android SDK at /Users/Michael/Library/Android/sdk
        • Platform android-30, build-tools 30.0.2
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 12.4)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 12.4, Build version 12D4e
        • CocoaPods version 1.10.1
    
    [✓] Android Studio (version 4.0)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin version 49.0.2
        • Dart plugin version 193.7547
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    
    [!] Connected device
        ! No devices available
    
    ! Doctor found issues in 1 category.
    

    ´´´

    After "flutter upgrade" I got the following message because of missing permissions (but I am admin and owner of flutter-directories):

    ´´´

    Unhandled exception:
    Exception: Flutter failed to create a directory at "/Users/michael/.config/flutter". The flutter tool cannot access the file or directory.
    Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.
    #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
    #1      _throwFileSystemException (package:flutter_tools/src/base/error_handling_io.dart:749:3)
    #2      _handlePosixException (package:flutter_tools/src/base/error_handling_io.dart:697:3)
    #3      _runSync (package:flutter_tools/src/base/error_handling_io.dart:561:7)
    #4      ErrorHandlingDirectory.createSync (package:flutter_tools/src/base/error_handling_io.dart:408:12)
    #5      new Config (package:flutter_tools/src/base/config.dart:33:17)
    #6      runInContext.<anonymous closure> (package:flutter_tools/src/context_runner.dart:146:21)
    #7      AppContext._generateIfNecessary.<anonymous closure> (package:flutter_tools/src/base/context.dart:104:41)
    #8      _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:311:23)
    #9      AppContext._generateIfNecessary (package:flutter_tools/src/base/context.dart:92:20)
    #10     AppContext.get (package:flutter_tools/src/base/context.dart:121:32)
    #11     config (package:flutter_tools/src/globals.dart:47:30)
    #12     getBuildDirectory (package:flutter_tools/src/build_info.dart:673:48)
    #13     defaultDepfilePath (package:flutter_tools/src/bundle.dart:29:55)
    #14     new BuildBundleCommand (package:flutter_tools/src/commands/build_bundle.dart:24:42)
    #15     new BuildCommand (package:flutter_tools/src/commands/build.dart:33:19)
    #16     main.<anonymous closure> (package:flutter_tools/executable.dart:102:5)
    #17     run.<anonymous closure> (package:flutter_tools/runner.dart:50:13)
    <asynchronous suspension>
    #18     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
    <asynchronous suspension>
    #19     AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
    <asynchronous suspension>
    #20     runInContext (package:flutter_tools/src/context_runner.dart:73:10)
    <asynchronous suspension>
    #21     main (package:flutter_tools/executable.dart:90:3)
    <asynchronous suspension>
    exit code 255
    

    ´´´

    When I now run "flutter doctor -v" I get the same failure "failed to create a directory at "/Users/michael/.config/flutter".

    When I run "sudo flutter doctor -v" I get:

    ´´´

    Woah! You appear to be trying to run flutter as root.
       We strongly recommend running the flutter tool without superuser privileges.
      /
    📎
    Downloading package sky_engine...                                  855ms
    Downloading flutter_patched_sdk tools...                            5,3s
    Downloading flutter_patched_sdk_product tools...                    5,4s
    Downloading darwin-x64 tools...                                    15,5s
    Downloading darwin-x64/font-subset tools...                      1.333ms
    [✓] Flutter (Channel stable, 2.0.1, on macOS 11.2.3 20D91 darwin-x64, locale de-DE)
        • Flutter version 2.0.1 at /Users/michael/Documents/Developer/flutter
        • Framework revision c5a4b4029c (8 days ago), 2021-03-04 09:47:48 -0800
        • Engine revision 40441def69
        • Dart version 2.12.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
        • Android SDK at /Users/michael/Library/Android/sdk
        • Platform android-30, build-tools 30.0.2
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
        • All Android licenses accepted.
    
    [!] Xcode - develop for iOS and macOS
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 12.4, Build version 12D4e
        ✗ CocoaPods installed but not working.
            You appear to have CocoaPods installed but it is not working.
            This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke
            it.
            This can usually be fixed by re-installing CocoaPods.
          To re-install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
    
    [✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google
        Chrome)
        ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
    
    [✓] Android Studio (version 4.0)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin version 49.0.2
        • Dart plugin version 193.7547
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    
    [!] Connected device
        ! No devices available
    
    ! Doctor found issues in 3 categories.
    

    ´´´

    When I run "flutter pub get" the same failure is shown:

    ´´´

    flutter pub get
    Unhandled exception:
    Exception: Flutter failed to create a directory at "/Users/michael/.config/flutter". The flutter tool cannot access the file or directory.
    Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.
    #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
    #1      _throwFileSystemException (package:flutter_tools/src/base/error_handling_io.dart:749:3)
    #2      _handlePosixException (package:flutter_tools/src/base/error_handling_io.dart:697:3)
    #3      _runSync (package:flutter_tools/src/base/error_handling_io.dart:561:7)
    #4      ErrorHandlingDirectory.createSync (package:flutter_tools/src/base/error_handling_io.dart:408:12)
    #5      new Config (package:flutter_tools/src/base/config.dart:33:17)
    #6      runInContext.<anonymous closure> (package:flutter_tools/src/context_runner.dart:146:21)
    #7      AppContext._generateIfNecessary.<anonymous closure> (package:flutter_tools/src/base/context.dart:104:41)
    #8      _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:311:23)
    #9      AppContext._generateIfNecessary (package:flutter_tools/src/base/context.dart:92:20)
    #10     AppContext.get (package:flutter_tools/src/base/context.dart:121:32)
    #11     config (package:flutter_tools/src/globals.dart:47:30)
    #12     getBuildDirectory (package:flutter_tools/src/build_info.dart:673:48)
    #13     defaultDepfilePath (package:flutter_tools/src/bundle.dart:29:55)
    #14     new BuildBundleCommand (package:flutter_tools/src/commands/build_bundle.dart:24:42)
    #15     new BuildCommand (package:flutter_tools/src/commands/build.dart:33:19)
    #16     main.<anonymous closure> (package:flutter_tools/executable.dart:102:5)
    #17     run.<anonymous closure> (package:flutter_tools/runner.dart:50:13)
    <asynchronous suspension>
    #18     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
    <asynchronous suspension>
    #19     AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
    <asynchronous suspension>
    #20     runInContext (package:flutter_tools/src/context_runner.dart:73:10)
    <asynchronous suspension>
    #21     main (package:flutter_tools/executable.dart:90:3)
    <asynchronous suspension>
    exit code 255
    

    Why I get these failures since "flutter upgrade" and why I can't debug anymore: "The Flutter Daemon has terminated. Cannot launch without an active device" ?

    • Moo
      Moo about 3 years
      and I can't start debugging. I get now the messages "The Flutter Daemon has terminated. Cannot launch without an active device"
    • Moghaddam
      Moghaddam about 3 years
      did you run "flutter upgrade" with sudo command?
    • Moo
      Moo about 3 years
      I tried "flutter upgrade" with and without sudo. Same result :(
    • Moghaddam
      Moghaddam about 3 years
      no no i think when you wanted to upgrade the flutter you ran it with sudo command and if you did so it has changed the flutter file permissions to root and that's why flutter can't access it
    • Moo
      Moo about 3 years
      how can I change permissions for /Users/Michael/.config/flutter on Mac?
    • Moghaddam
      Moghaddam about 3 years
      "chown USER FILE" change the ownership of a file so in case of you : "chown michael /Users/michael/.config/flutter"
    • Moo
      Moo about 3 years
      thank you! I tried "chown michael /Users/michael/.config/flutter" with and without sudo. Without sudo it says "Permission denied". With sudo it returns nothing. The behavior is still the same. Says failed create directory for "flutter doctor" and "flutter pub get": "Exception: Flutter failed to create a directory at "/Users/michael/.config/flutter". The flutter tool cannot access the file or directory. Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user. "
    • Moo
      Moo about 3 years
      I downloaded flutter again, but still the same behavior
    • Moghaddam
      Moghaddam about 3 years
      can you provide the output of this command:"ls -ld /Users/michael/.config/flutter"
    • Moo
      Moo about 3 years
      "ls -ld /Users/michael/.config/flutter" says: drwxr-xr-x 2 michael staff 64 6 Mär 17:08 /Users/michael/.config/flutter
    • Moghaddam
      Moghaddam about 3 years
      sry i forgot this flag can you run this command again: "chown -R michael /Users/michael/.config/flutter"
    • Moo
      Moo about 3 years
      I did run "sudo chown -R michael /Users/michael/.config/flutter" again. "sudo ls -ld /Users/michael/.config/flutter" still says: drwxr-xr-x 2 michael staff 64 6 Mär 17:08 /Users/michael/.config/flutter
    • Moghaddam
      Moghaddam about 3 years
      check if you still have the problem i think everything must be ok now
    • Moo
      Moo about 3 years
      I still have the problem. I restarted the Mac. still the same problems. what now?
    • Moo
      Moo about 3 years
      is it relevant which shell I use? I had to change from bash to zsh.
    • Moghaddam
      Moghaddam about 3 years
      no it's not. ok run this two command hope we solve this: "sudo chown -R $USER:$USER Users/michael/.config/flutter" and "sudo chmod 754 Users/michael/.config/flutter"
    • Moo
      Moo about 3 years
      thank you! but still the same failure
    • Moghaddam
      Moghaddam about 3 years
      is problem still related to the that folder? if so simply uninstall the os :)) ok give it the last shot: "sudo chmod -R 777 /Users/michael/.config/flutter" there is no way around man this must work
    • Moo
      Moo about 3 years
      Thank you! Still the same failure-message. I guess I have to uninstall the os :(
    • Moghaddam
      Moghaddam about 3 years
      it is impossible man we have given all users full permission to that folder. can you check if the problem still related to that folder or not and if so can you provide the output of this command again: "ls -l /Users/michael/.config/flutter" (output might be a bit long)
    • Moo
      Moo about 3 years
      The problem still exists: flutter doctor Unhandled exception: Exception: Flutter failed to create a directory at "/Users/michael/.config/flutter". The flutter tool cannot access the file or directory. The command "ls -l /Users/michael/.config/flutter" says "Permission denied". The command "sudo ls -l /Users/michael/.config/flutter" gives no answer.
    • Moghaddam
      Moghaddam about 3 years
      can you provide the output of this command again:) "ls -ld /Users/michael/.config/flutter" and i should have say it sooner btw for security reasons don't ever run a command with 'sudo' unless it requires root privilege it's quite dangerous man so run the command above without sudo
    • Moo
      Moo about 3 years
      "ls -ld /Users/michael/.config/flutter" says Permission denied
    • Moghaddam
      Moghaddam about 3 years
      what about this "ls -ld /Users/michael/.config"
    • Moo
      Moo about 3 years
      It is root! drwx------ 4 root staff 128 6 Mär 17:08 /Users/michael/.config
    • Moghaddam
      Moghaddam about 3 years
      ok run "sudo chown michael /Users/michael/.config" and then "ls -ld /Users/michael/.config/flutter"
    • Moo
      Moo about 3 years
      "sudo chown michael /Users/michael/.config" made success and "flutter doctor" runs without failure. thank you man!
    • Moghaddam
      Moghaddam about 3 years
      we have done it:) and remember no sudo unless it requires. happy coding:)
    • Moo
      Moo about 3 years
      yes you done :) thank you for your patience! info: debugging worked after restart of VSCode again too
    • Moghaddam
      Moghaddam about 3 years
      you're welcome have a nice day:)
    • Moo
      Moo about 3 years
      have a nice day too :)
  • Rehan Ali
    Rehan Ali almost 3 years
    You shouldn't use sudo with flutter because google discourages it.
  • Jithin U. Ahmed
    Jithin U. Ahmed almost 3 years
    @RehanAli : I appreciate, but actually this was the only method that solved mine.
  • Rehan Ali
    Rehan Ali almost 3 years
    I just got this issue and fixed it by installing flutter without root as a regular user. After that I simply run flutter precache and by the time it finishes, everything is working fine. You Encounter this issue because flutter is available with some other user and your user is different, that's why it needs root access.