115

Recently I updated Mac OS to latest Catalina. Now when entering a flutter command like the following,

flutter --version

my terminal (which is using zsh) shows me following error:

zsh: command not found: flutter

How do I reinstate the path to allow flutter commands from any directory?

D. Greg
  • 991
  • 1
  • 9
  • 21
Code Hunter
  • 10,075
  • 23
  • 72
  • 102
  • first answer ok, but for who does not like vim here is other way for Ubuntu users: 1. open terminal ``` ctrl + alt + t ``` 2. `` nano $HOME/.zshrc ``` 3. at the end of the file add the following line ( please replace [flutter_dir] with your director ``` export PATH=$PATH:[flutter_dir]/flutter/bin ``` 4. exit -> save ``` ctrl + x ``` 5. source ~/.zshrc – ElsayedDev Nov 03 '22 at 20:05
  • This question is clearly relevant to software tools primarily used by programmers. The fact that as of today it has 90 upvotes and that the most-upvoted answer has 305 upvotes shows how many people have found this question useful. – ClayJ Nov 12 '22 at 23:25
  • In my case, my problem was the relative path to the flutter folder. I changed it to the absolute path and it was all fine. – cansu Feb 27 '23 at 15:52
  • 1
    This question shouldn't have been closed. – Mahesh Jamdade Jun 12 '23 at 22:48
  • This question shouldn't have been closed – Heshan Sandeepa Jun 17 '23 at 23:10

14 Answers14

377

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 ~.

Basheer AL-MOMANI
  • 14,473
  • 9
  • 96
  • 92
Murad Al Wajed
  • 4,180
  • 1
  • 10
  • 11
91

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

iamnagaky
  • 1,033
  • 7
  • 7
58

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

surhidamatya
  • 2,419
  • 32
  • 56
41

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

Marcos Boaventura
  • 4,641
  • 1
  • 20
  • 27
  • 6
    For others wondering...(stupid me, but) the 'restart terminal session' did the trick for me. (do the same in Android Studio of Visual Studio Code!) – R. Flierman Jan 08 '20 at 20:30
  • 1
    Same here. The post important part "restart your terminal session." Or you could spend extra 1 hour. – Atakan Akbulut Aug 25 '22 at 07:34
29

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
user3305074
  • 744
  • 7
  • 19
  • Any explanation why removing quotes helps? – anber Jan 26 '22 at 10:32
  • 1
    @anber: Bcz it contains a variable $PATH, which would resolve to actual path localtion. if you still want to use "" then replace $PATH with actual path. Hope it helps. – user3305074 Jan 30 '22 at 05:48
14

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

Mohammad Alotol
  • 1,409
  • 15
  • 23
12

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

Soroush
  • 541
  • 4
  • 17
MikeFranks
  • 121
  • 3
  • this is because some other exports have messed your zsh profile. Who experience similar issues - check if you have messed lines like 'export PATH=/opt/homebrew/bin$PATH' and change them to export PATH=/opt/homebrew/bin/:$PATH - notice : symbol before PATH – Eugene Martinson Mar 06 '22 at 09:03
10

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
    
Dharman
  • 30,962
  • 25
  • 85
  • 135
labr4t
  • 101
  • 1
  • 2
8

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

Yuri
  • 327
  • 5
  • 7
6

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

Abed Putra
  • 1,153
  • 2
  • 17
  • 37
4

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.

Code Hunter
  • 10,075
  • 23
  • 72
  • 102
3

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.

Doan Bui
  • 3,572
  • 25
  • 36
3

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

zaffar
  • 679
  • 6
  • 13
3

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

devsandesh
  • 41
  • 1