how to fix "bash: flutter: command not found" error?

2,253

It's possible that the environment variable, that was previously set, got cleared at some point and that's why the Flutter command is not recognized.

In any case, one way to make sure that Flutter is in your profile is to add it to your path within your ~/.bash_profile (bash profile) file. The ~/.bash_profile is a script gets executed every time you open Git Bash.

Adding Flutter to your Bash Profile

  1. Open your ~/.bash_profile file for editing:
$ nano ~/.bash_profile
  1. Add to the top of your ~/.bash_profile file, the following lines:
# Add Flutter to PATH
PATH=/path/to/flutter/bin:$PATH

# Add Dart to PATH
PATH=/path/to/flutter/bin/cache/dart-sdk/bin:$PATH

Replace /path/to/flutter, with the absolute path of your Flutter installation directory.

  1. Apply the changes:
$ source ~/.bash_profile

Ensuring Git Bash is opened for non-login shells
(Credit: Charles Duffy)

$ echo "source ~/.bash_profile" >> ~/.bashrc
Share:
2,253
Ashish Bhardwaj
Author by

Ashish Bhardwaj

Updated on December 02, 2022

Comments

  • Ashish Bhardwaj
    Ashish Bhardwaj 11 months

    I have been working on flutter using VScode with all environment variables set on Windows OS. Now i upgraded the flutter using "flutter upgrade" in Git Bash terminal of VScode to the stable version and now i am not able to use flutter commands in Git Bash terminal of VScode. I wonder where things could have gone wrong , how do i fix it ?

    I re-verified that all my environment variables are set correctly according to official documentation. Also flutter commands are running perfectly through flutter console .

    Ashish@DESKTOP-3JFCI3M MINGW64 ~/Desktop/Flutter Exercise/test_2
    $ flutter doctor
    bash: flutter: command not found
    

    Edit: Made changes to the "~/.bash_profile" as mentioned by Sam , still getting the same error . Also i re-checked and the environment variables are set there already. Any ideas what i could do further to fix it ? Thanks in Advance :) Also when executed command of step no 3. source ~/.bash_profile , output is

    $ source ~/.bash_profile
    bash: C:DEVLOPMENTflutterbin: command not found
    bash: C:DEVLOPMENTflutterbincachedart-sdkbin: command not found```
    
    • Gazihan Alankus
      Gazihan Alankus over 4 years
      There, write echo %PATH%. That will give you a list of directories. One of them needs to contain flutter.bat for flutter to work. Maybe if you changed your path variable recently, a reboot maybe a sure way to apply that.
    • SamJakob
      SamJakob over 4 years
      @GazihanAlankus He's using Git Bash and you've given him a Windows command prompt command. To see it, he'd need to do echo $PATH
    • tripleee
      tripleee over 3 years
      The final message indicates that you have backslashes instead of forward slashes. This makes sense on Windows, but the backslash is a metacharacter in Bash, so you need to single-quote the string with backslashes, or escape each backslash with another backslash. But even Windows itself accepts forward slashes instead so probably that's the simplest fix. (Tempted to suggest ditching Windows as even simpler in the long run.)
  • Charles Duffy
    Charles Duffy over 4 years
    Opened for every login shell. Not every interactive shell is a login shell. You'd want to have your .bashrc source .bash_profile to make sure it's run for both types.
  • Charles Duffy
    Charles Duffy over 4 years
    And BTW, there's no point to re-exporting something that's already in the environment. Just PATH=/path/to/flutter/bin:$PATH will have the same effect.
  • SamJakob
    SamJakob over 4 years
    Updated @CharlesDuffy - though I'm fairly certain Git Bash always opens a login shell.
  • Gel
    Gel over 2 years
    please mark as the right answer if this helped.