13

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.

Terry Feng
  • 131
  • 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,438
  • 1
  • 15
  • 34
  • 1
    .bashrc files is not found in my case please help ;( – Pratik Gondil Nov 30 '18 at 09:11
  • 1
    user@linux:-$ ls -la | grep -i ".bashrc" (firstly, use this command to verify ".bashrc" do exists or not in you home root dir) – sparsh Nov 30 '18 at 09:14
  • it present in the directory but running the .bashrc it gives permission denied. i already pemission read and write on home – Pratik Gondil Nov 30 '18 at 10:06
  • 1
    it’s clear then, you need sudo permission to access bashrc file. Alternatively you can also use “.profile” file instead of bashrc which also happens to reside in same Home root dir. :) – sparsh Nov 30 '18 at 10:11
  • all set but after run it gives this exception please run 'flutter doctor' for information about installing additional components. – Pratik Gondil Nov 30 '18 at 10:25
  • kasunix@kasunix-Inspiron-N4030:~$ flutter doctor Error: Unable to find git in your PATH. – TipVisor Apr 14 '20 at 06:13
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,959
  • 2
  • 15
  • 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 P Raju
  • 3,879
  • 14
  • 101
  • 136
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
  • 296
  • 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,021
  • 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,701
  • 9
  • 50
  • 89
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

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
  • 16,071
  • 12
  • 120
  • 159
0

Flutter Path Setup in MAC

Before Setup Clone the git Flutter Folder using below Command

==> git clone https://github.com/flutter/flutter.git -b stable

Step 1: Copy the Path of " Git Flutter Folder" and make PATH variable like below

==> export PATH="$PATH:/Users/myhome/Desktop/Flutter/bin"

Step 2: type "echo $SHELL" in terminal.It will show the type of shell which is using in your Mac

Step 3: If it is bash, type "open .bash_profile" in terminal to open the hidden "rc" file

step 4: once opened, copy the Path variable from step 1 and paste it in .bash_profile file

Step 5: save the file

Step 6:run ==> source $HOME/.bash_profile

Step 7: Now check your path got updated by ==> echo $PATH command

Step 8:once it got listed run ==> Flutter Doctor

Step 9: If error occurs like "flutter commands not found" then "RESTART" your Mac

Now try Flutter Doctor it will work

Subathra D
  • 389
  • 3
  • 7