12

I've been trying to set a flutter path so I don't need to do a temporary path every single time. I'm new to using terminal and Unix (Mac user also) and don't understand how to set my path with the instructions on the site. And it doesn't help that I'm not completely sure where I out my flutter sdk. Would like to know step by step what to do.

Paresh Mangukiya
  • 37,512
  • 17
  • 201
  • 182
Terry Feng
  • 121
  • 1
  • 1
  • 3

10 Answers10

42

I'm using Ubuntu 18.04 LTS. Assuming you have successfully downloaded and extracted flutter_linux_v0.5.1-beta.tar.xz (latest update until now) onto your preferred directory.

export PATH=`pwd`/flutter/bin:$PATH

Running this command in your ubuntu terminal (Ctrl + Alt + T) adds flutter commands PATH variable to your system path for temporary session. As soon as you close the terminal, the system path is removed.

In order for ubuntu terminal to remember flutter commands permanently, you need to:

1.) open up terminal and cd to $HOME. for eg: user@linux:~$

2.) open the hidden file .bashrc with your desired editor. It resides in $HOME.

3.) add the following line export PATH=/home/yourname/flutter/bin:$PATH somewhere as a newline in .bashrc file preferably as a last line edit & save file.

4.) run source /home/yourname/.bashrc in terminal to process your recent changes.

5.) finally, run echo $PATH to see flutter dir is in your system path along with other such paths. for eg: /home/yourname/flutter/bin

Now close current terminal and reopen new terminal to check flutter doctor. It should process along with all other available flutter commands everytime now onwards. Thank you ! :)

sparsh
  • 1,336
  • 1
  • 16
  • 33
4

Windows
Refer to this tutorial https://www.java.com/en/download/help/path.xml

Mac OS
Open or create one the following files:

  • ~/.profile (Compatible with MacOS Catalina)
  • .bash_profile (Only if your Terminal uses Bash)
add the following line at the bottom.
export PATH=$PATH:/flutter/bin

Linux
Open or create ~/.bash_profile add the following line at the bottom.

export PATH=$PATH:/flutter/bin

Linux (Ubuntu 19.04)
Open ~/.bashrc add the following line at the bottom: (your path may be different)

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

For further documentation

https://flutter.io/docs/get-started/install/macos#update-your-path

hysabone.com
  • 2,501
  • 2
  • 11
  • 26
2
export PATH=`pwd`/flutter/bin:$PATH
2

I had the same issue when i am working VS Code / flutter with ubuntu OS. every time shows the message flutter: command not found . Then i set the path through VS Code integrated terminal. Please see the below screenshot.

enter image description here

Ragesh S
  • 3,727
  • 13
  • 99
  • 131
2

open a terminal window and write command vim ~/.bash_profile Write this in the file.

alias flutter="~/flutter/bin/flutter" 

if you have extracted flutter in your root (~) folder.

save this and run this command in terminal.

source ~/.bash_profile

Now you are done.

Divyansh Gupta
  • 261
  • 3
  • 10
2

I'm using macOS Catalina version- 10.15.7 and I have updated my $PATH variable by following those steps:

  1. Optional: Type echo $SHELL in your terminal. It will tell you which shell you are using. macOS Catalina uses Z shell by default. Output: /bin/zsh
  2. Optional: Type echo $PATH in your terminal and hit enter. It will show you the existing paths you have already set as path variable. Output: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
  3. As i'm using Z shell i have to open the .zshrc file. In my case i'm using vim editor. You can also use nano or atom editor. For opening the file type vi ~/.zshrc in your terminal.
  4. Type i for Insert mode.
  5. Type export PATH="$PATH:[your_flutter_sdk_path_here]/flutter/bin"
  6. To save the file in Vim/vi, press Esc key then type :w and hit Enter key.
  7. To quit Vim/vi by press Esc key then type :x and hit Enter key.
  8. Finally you need a dot notation to activate it. Type . ~/.zshrc in your terminal.

Now you can check your path variable by typing echo $PATH in your terminal and hiting enter key.

Output: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin:/Users/user/Documents/flutter/bin

Verify that the flutter command is available by running which flutter in your terminal.

Output: /Users/user/Documents/flutter/bin/flutter

Torongo
  • 1,001
  • 1
  • 7
  • 14
1

You can add the Flutter path to the system path or to your ~/.profile file.

This will help you as it has more detailed instructions, difference on using .profile vs .bashrc and usage on different shells.

https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path

Purus
  • 5,449
  • 8
  • 45
  • 85
0

it depends what shell you use,if you use bash,you can edit ~/.bash_profile,add environment variable as export PATH=xxx/flutter/bin:$PATH;if use zsh,you should edit ~/.zshrc ,add environment variable as export PATH=xxx/flutter/bin:$PATH

ThomasLee
  • 17
  • 5
0

How to Install Flutter on MacOS : https://www.youtube.com/watch?v=ZwUGHiroGBo

To permanently add Flutter to your path, follow this command line

  1. Open (or create) the rc file for your shell. Typing echo $SHELL in your Terminal tells you which shell you’re using. 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.

    In your terminal, run:

    touch $HOME/.bash_profile
    
    vi $HOME/.bash_profile
    

In Catalina your default shell is ZSH, thus you can also replace the '(dot)bash_profile' to '(dot)zshrc' [without quote and replace the dot] and the rest is the same!

Also to check for environment is running, you can just type 'flutt' + TAB, and if autocomplete kicks in you are done!

  1. Add the following line and change [Flutter SDK] to be the path where you extracted Flutter SDK and save

    If this is not working:

    export PATH="$PATH: /Users/Desktop/flutter/bin"
    

    Try this instead:

    export PATH="$HOME/Users/Desktop/flutter/bin:$PATH"
    

Save the file and close it.

  1. Run source $HOME/.bash_profile to refresh the current window, or open a new terminal window to automatically source the file.

  2. And verify that the flutter/bin directory is now in your PATH by running:

    echo $PATH
    

    Verify that the flutter command is available by running:

    which flutter
    

It's done successfully for me

enter image description here

Paresh Mangukiya
  • 37,512
  • 17
  • 201
  • 182
0

For bash profile users

Step 1: open terminal and type

vim ~/.bash_profile

Step 2: Type this command (modify your folder path)

Note: I added one new folder(FlutterSDK) in my username

export PATH="$PATH:$HOME/FlutterSDK/flutter/bin"

Step 3: Press esc

Step 4: type :wq! command to save this bash file

:wq!

Step 5: Close current terminal window & open new window

Step 6: To verify type flutter version command

flutter --version
Ranjithkumar
  • 14,780
  • 10
  • 107
  • 140