Flutter development - installation and environment configuration - configuration environment variable failure problem (Mac terminal reports: zsh: command not found: flutter )

Flutter development - installation and environment configuration - configuration environment variable failure problem (Mac terminal reports: zsh: command not found: flutter )


flutter

foreword

Flutter official website installation and environment configuration column address: Install and configure Flutter development environment on macOS

Operating environmentMacOS Monterey

When referring to the installation and configuration section of the Flutter official website, configure the .bash_profile file of the mac system, as follows:

Open a new terminal and enter the following command:

flutter doctor

报 zsh: command not found: flutter

reason

The reason is that starting from the MacOS Catalina version, Mac will use zsh as the default login shell and interactive shell. zsh can only be set as the default shell in lower versions of MacOS.

What do you mean? It means that in systems higher than MacOS Catalina, the environment configuration has changed to a file, so when I enter flutter doctor , the system cannot find it.

solve

  • Single solution:

    When we need to use it, open the terminal and enter:

    source ~/.bash_profile

    Then execute:

    flutter doctor

    That's it, but note that this can only take effect in the current terminal. When you close and reopen the terminal, it will be invalid and you have to re-enter "source ~/.bash_profile" to take effect.

  • Permanent solution (with permission to modify files):

    So is there any permanent solution? Yes, the specific permanent solution will be introduced in detail next:
    Open the terminal and enter:

    open ~/.zshrc

    After opening, copy .bash_profile into the opened file, then save it and close it. Enter in the terminal:

    source ~/.zshrc

    Just reload and you're done. In the future, as long as you open the terminal, the flutter command will be able to recognize it.

  • Permanent solution (modify files without permission)

    When we open the zshrc file according to the previous step, when we copy the content of .bash_profile and save it, the system will report that it is currently read-only, and the current user has no permission to modify it, as follows:

    insert image description here
    If this happens, then we can only modify it through the terminal. Type in terminal:

    vim ~/.zshrc

    When we press Enter to execute, the terminal will prompt as follows:

    As can be seen from the green text at the bottom, we can modify the file by typing " e " on the keyboard, as follows:


    We need to enter " i " on the keyboard to become editable (the INSERT keyword at the bottom)


    Then we paste the contents of .bash_profile into this text, press the " esc " key on the keyboard, and then enter " :wq ", and press Enter to save the file.

    At this point, it is the same as the permission solution above, and the terminal enters:

    source ~/.zshrc

    Just reload and you're done.

attach

When the terminal executes " flutter doctor --android-licenses " to agree to the Android protocol, the terminal reports an error:

insert image description here
This is because Android Studio did not check the Android Sdk Commend-line Tools, after clicking the check, restart Android Studio

Summarize

The above is about the records and solutions of the problems encountered in installing and configuring Flutter on Android on MacOS.

If there is something wrong or wrong, please point it out!

The code word is not easy, please like it!

Guess you like

Origin blog.csdn.net/weixin_43683367/article/details/127600058