Flutter commands not working

2019-03-18 03:05发布

问题:

bash: flutter: command not found

Hi everyone! Apparently none of the flutter commands are working on the terminal of android studio which I believe I am trying to run it at the root of my project. Thank you in advance

回答1:

You need to correctly set up your flutter path.

from here https://flutter.io/setup-macos/#update-your-path

  1. Determine the directory where you placed the Flutter SDK. You will need this in Step 3.
  2. Open (or create) $HOME/.bash_profile. You can do that by using terminal text editor by going in terminal and typing nano ~/.bash_profile

  3. Add the following line and change [PATH_TO_FLUTTER_GIT_DIRECTORY] to be the path where you cloned Flutter’s git repo:

export PATH=[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin:$PATH

for example:

export PATH=~/Documents/flutter/bin:$PATH

  1. press CTRL X and when it asked you to save the file, choose yes

  2. Run source $HOME/.bash_profile to refresh the current window or restart the terminal

  3. Verify that the flutter/bin directory is now in your PATH by running: echo $PATH

Notice that [PATH_TO_FLUTTER_GIT_DIRECTORY] is where you installed flutter sdk, not the location of your app

Instead of nano, you can use any text editor to edit ~/.bash_profile



回答2:

Do the following steps:

  1. Download the Flutter SDK Flutter SDK Archive

  2. Extract it where do you want (for example /home/development/flutter)

  3. Set your PATH, edit your file with this command gedit ~/.profile, you need to add this line

export PATH=[location_where_you_extracted_flutter]/flutter/bin:$PATH

I showed you above where I've extracted mine, so my export will look like this

export PATH=/home/myUser/development/flutter/bin:$PATH
  1. Save the file and close it.
  2. Run source ~/.profile to load the changes
  3. If you run now flutter doctor should work!


回答3:

Tried out all the above methods, but all of them lasted only until the terminal was open. So I went ahead and directly added it to the path file permanently.

sudo nano /etc/paths

add this to the file

/Users/yourUserName/Development/flutter/bin

Save the file, Tada!



回答4:

You must have .bash_profile file and define flutter path in .bash_profile file.

  1. First of all, if you do not have or do not know .bash_profile, please look my answer: How do I edit $PATH (.bash_profile) on OSX?

  2. You should add below line(.../flutter_SDK_path/flutter/bin) in your .bash_profile

export PATH=$PATH:/home/username/Documents/flutter_SDK_path/flutter/bin

After these steps, you can write flutter codes such as, flutter doctor, flutter build ios, flutter clean or etc. in terminal of Macbook.

@canerkaseler



回答5:

You can easily create a symbolic link as below,

sudo ln -s /opt/flutter/bin/flutter /usr/bin/flutter

I had moved flutter into /opt/ folder after downloading, so replace with the path you have flutter directory.

flutter command should work even after rebooting your machine.



回答6:

Ubuntu 16.04 :-

I added the path correctly for Flutter, Java, Android Studio and Android SDK in .bashrc file , but when I run flutter doctor, the terminal returns

flutter: command not found

Solution :-

So,first I had to always run ->

sudo su

then ->

source /home/your_name/.bashrc

Then run flutter doctor, it works fine.

So everytime, If I want to run flutter doctor, I have to run these above 2 commands.

Hope it helps :)



回答7:

I faced this problem and I resolved it following these steps:

  1. : nano ~/.bash_profileexport

  2. : add this line: PATH=/Users/user/Documents/flutter_sdk/flutter/bin:$PATH make sure the dir to your flutter bin is correct.

  3. :source ~/.profile



回答8:

On the mac I followed the steps of the user Tree but still received the answer "flutter: command not found". What I did next was, go to the folder flutter/bin and inside this folder ctrl+click on flutter executable and in the popup i clicked open. After that the mac already recognized this as an exception and the flutter commands already work.



回答9:

For Ubuntu 14.*

there is no .bash_profile file but it just a .profile in /home/mangesh

In my case,I am running this command to add flutter/bin path,

export PATH="$PATH:/home/mangesh/Documents/flutter_data/flutter/bin/"

To verify above change just run,

echo $PATH

Following is my complete output,

mangesh@Mangesh:~$ pwd
/home/mangesh

mangesh@Mangesh:~$ export PATH="$PATH:/home/mangesh/Documents/flutter_data/flutter/bin/"

mangesh@Mangesh:~$ echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/mangesh/Documents/flutter_data/flutter/bin/


回答10:

Add Path in this way in .bashrc of android sdk and tools with flutter

export PATH=$PATH:/user/Android/Sdk/platform-tools:/user/Android/Sdk/build-tools/27.0.1:/user/Android/Sdk/tools:/user/Android/Sdk/tools/bin:/user/Documents/fluterdev/flutter/bin:$PATH

Then run this command

source ~/.profile

Then you can user any of flutter command like to build fluter apk

flutter build apk



标签: dart flutter