MacOS 给出 zsh: command not found: Flutter 后更新路径,根据 Flutter 的官方文档

最近我更新了 Mac OS 到最新的 Catalina 和我的终端,现在使用 zsh 开始显示我以下错误:

zsh: command not found: flutter

在更新之前一切正常。

141449 次浏览

You must update your environment $PATH variable.

1) Open the file $HOME/.zshrc $HOME is your home path

2) add the following line in the opened file:

export PATH="$PATH:/YOUR_FLUTTER_DIR/flutter/bin"

3) save the changes and restart your terminal session.

The process is also documented here

I followed URL to resolve my issue.

I simply created a .zshrc file which was not exist then added my PATH variables copied from existing .bashrc.

I updated from Mojave to Catalina and running Terminal, switched to the default/preferred zsh shell, from the bash shell. Then was hit with

zsh: command not found: flutter

so, followed the advice seen elsewhere to only add the following to Users/MyUserId/.zshrc

export PATH="$PATH:/YOUR_FLUTTER_DIR/flutter/bin"

echo $PATH showed that /Users/MyUserId/flutter/bin was now one of the configured PATHs. However, I couldn't get "flutter doctor" to work but came across a post on jelliesgame.com which suggested copying

Users/MyUserId/.bash_profile to Users/MyUserId/.zshenv

Now, flutter doctor gives a clean bill of health

You need to update the environment path.

  1. Open terminal.

  2. vim $HOME/.zshrc

  3. Press "I" key for going to insert mode.

  4. add the following line in the opened file:

    export PATH="$PATH:/YOUR_FLUTTER_DIR/flutter/bin"

  5. Press "Esc" then write :wq! in terminal and press enter to exit vim.

  6. Reopen the terminal and check "flutter doctor"

If this solution did not work, remove the double quote from path or use the full path explicitly instead of ~.

Had the same issue and just realized that I forgot to add the close quote

So the correct way is to add to .zshrc by typing vim ~/.zshrc

PATH="$PATH:$HOME/Flutter/flutter/bin"

or

export PATH="$PATH:/YOUR_FLUTTER_DIR/flutter/bin"

then run source ~/.zshrc or just open a new terminal window

I had the same problem when upgrading to mac Catalina 10.15.4:

After many days of research, I have achieved success. Here are the steps I did:

First, open the terminal on your mac.

Next, use the command

 cat .bash_profile

and copy the content.

Then type this command into the terminal:

nano $ HOME / .zshrc

and paste the content just copied above into. Save then type

source $ HOME / .zshrc

to refresh this file. Next type

echo $ PATH

to see if the content has been updated. If successful type

flutter --version

and you will see the result.

I tried installing flutter on my MAC according to the advice here, but it still doesn't work, after searching for it I found an article here.

So, I change my .zshrc file to:

export PATH="$PATH:/Users/YOUR_PROVILE_NAME/YOUR_DEVELOPMENT_FOLDER/flutter/bin"

Change YOUR_PROVILE_NAME to your name profile, also YOUR_DEVELOPMENT_FOLDER to your development folder for flutter

and now it's working.

Note: I use Catalina OS v10.15.4

Working on macOS Catalina 10.15.5 (19F101). I have used .zprofile instead of .zhrc

  1. Provide Full Disk Access to Terminal by Setting -> Security & Privacy -> Full Disk Access. Add Terminal

  2. If the current terminal uses bash, change to zshell using the below command

    chsh -s /bin/zsh

  3. In the root directory i.e something like /Users/^YourAccount^ execute the below

    touch .zprofile

    vim .zprofile

  4. Press I to enter insert mode. Type the below

    export PATH=$PATH:/Users/^YourAccount^/^YourPath^/flutter/bin

  5. Save and quit by pressing Esc, then :wq and Enter

  6. Close Terminal and reopen Again. Then try executing flutter command

Follow these steps:

Open finder Enter Cmd + Shift + G

Type ~ in Go to the folder popup.

Now enter Cmd + Shift + . to show hidden files.

Open .zshrc

Add this line

export PATH="$PATH:/YOUR_FLUTTER_DIR/flutter/bin"

Replace this /YOUR_FLUTTER_DIR with the path to your flutter directory. In my mac, the path is

export PATH=$PATH:$HOME/FlutterDevelopment/flutter/bin

For me removing double quotes did the fix.

Try changing

export PATH="$PATH:[PATH TO FLUTTER]/flutter/bin"

into

export PATH=$PATH:[PATH TO FLUTTER]/flutter/bin

adding few more steps for easiness:

Open terminal.

vim $HOME/.zshrc

Press "I" to open insert mode.

add the following line in the opened file:

export PATH=$PATH:[PATH TO FLUTTER]/flutter/bin (remember I don't have double quotes here)

Press "Esc" then type :wq in terminal to exit edit mode.

Type source .zshrc to reload the terminal for changes

There are quite a few answers mentioned above pretty much same. I would say worth seeing into the SHELL using echo $SHELL command,

If you’re using Bash, edit $HOME/.bash_profile or $HOME/.bashrc. If you’re using Z shell, edit $HOME/.zshrc. If you’re using a different shell, the file path and filename will be different on your machine.

N.B. Don't forget you need to add VIM before either command in the terminal app.

For further details, click the link Update your path, and look into the section Update your Path. I hope it would help many especially new comers to MAC OS. Cheers

For me .zshrc worked instead of .zprofile. I believe this is because I had created .zshrc earlier and now when I tried creating .zprofile, it was looking into .zshrc file.

You can check if .zshrc file using ls -a command

in android studio terminal, simply just type this command:

export PATH="/YOUR_FLUTTER_DIR/flutter/bin:$PATH"

change YOUR_FLUTTER_DIR to your actual directory

This worked for me:

Steps:

  1. Type on the terminal:
    open .zshrc (This opens the document in text edit)
    
  2. Add this to the end of the file:
    export PATH="/Users/YOUR_USERNAME/Documents/code/tools/flutter/bin:$PATH"
    
  3. Save and close .zshrc
  4. Then type:
    flutter doctor