Nowadays few developers are facing an error, named ‘command not found: flutter’. If you are also facing such type of issue then this guide might help you in fixing this issue efficiently.
First of all, let’s explore a few terminologies before jumping to the solution.
What is Flutter?
Flutter is a free and open-source mobile UI framework made by Google. It come into existence in May 2017. In a couple of words, it permits you to build native mobile apps with a single codebase. This means that you can use the same programming language and the same codebase to create two different apps (for iOS and Android).
Flutter comprises two significant parts:
- An SDK (Programming Improvement Unit): A set of tools that will help you develop your application. This includes tools to compile your code into native machine code (code for iOS and Android).
- A Structure or framework (UI Library based on widgets): A collection of reusable UI components (buttons, text inputs, sliders, etc) that you can customize for your own requirements.
To develop with Flutter, you will utilize a programming language called Dart. The language was made by Google in October 2011, yet it has worked significantly over these previous years.
Dart centers around front-end development, and you can use it to make mobile and web applications.
Command Not Found: Flutter
However, in the program where there is an issue with the executable, you could get the error:
command not found: flutter
We should explain the root cause of the error, what you really want to be familiar with the $PATH variable and how to troubleshoot the issue.
What does the error mean?
The error implies something simple: your shell (slam, zsh, or anything shell you are utilizing) is letting you know that it investigated the $PATH, yet couldn’t track down an executable named flutter. Suppose you downloaded flutter and place it in a folder called “flutter” in your home envelope ($HOME/flutter). You have to tell your shell to look for a file to work with because it doesn’t know that itself.
Where does the OS look for Flutter?
At the point when you type a command – it can be any command you enter into your shell – the primary thing the shell will do is to search inside its $PATH for an executable with the very name you entered.
The significant part is that there are a lot of folders that are set default, however, to make another command accessible, you need to expand the $PATH variable by the new directory and in this manner loo it to look there too.
We should take a gander at how to set the way factor on various working frameworks.
In Windows, using the shell is not popular. Instead. most of the time you work with the operating system’s GUI. I will make sense of the two different ways, beginning with the GUI:
- Using the keyboard shortcut Windows + X, you will access the advanced user action menu.
- Select the System option.
- Scroll down and click About.
- Click the System Settings text button at the top of the device description.
- Click the Advanced tab, then click the Change Environment button at the bottom.
- Select the variable path in the Variable System field and click the Edit button.
- There you can add or edit the path lines and paths you want the operating system to access. Separate the paths with a semicolon.
On the off chance that you like to set such choices by means of the CLI, you can do this with a basic command: setx.
You must run it from a privileged CLI.
To do this, right-click on the cmd shortcut (eg. Windows key, then type “cmd“) and select “Run as administrator”.
If your Flutter directory is ‘C:\Downloads\Flutter‘, you should set it up like this:
setx /M PATH "%PATH%;C:\Downloads\Flutter\bin\flutter"
Using/ M as a choice will play out the difference in PATH in HKEY_LOCAL_MACHINE rather than HKEY_CURRENT_USER, which makes it a framework-wide change and not just a client change.
NOTE: setx truncates a stored path string to 1024 bytes (which equals 1024 characters). This can cause data loss if the path is already around 1024 bytes or more! If you're not sure, use echo %PATH% to read it first.
Linux (with ZSH)
In a Linux distribution, unlike Windows, there is no single source of truth. Instead, there is an operating system configuration that loads files at startup, which can change $PATH. Some files come from different locations, so it’s good to know when to change which.
The source file is in this order:
.zshenv gets it in all cases. If environment changes are set, they should be updated frequently. It is also used for export variables that should be read by other applications such as $EDITOR, $PAGER and our favorite: $PATH.
Keep in mind that this file is accessed even when zsh starts executing a command, as well as by other programs e. g. Create. You need to know what you are doing because you can break the standard rules or commands.
.zshenv also allows you to specify a new location for the remaining zsh configuration. You can do this by setting $ZDOTDIR.
Since .zprofile is used for login protection, it is usually issued only once. It is an alternative to .zlogin (which comes two steps down) that should be used instead for changes that are not updated frequently.
The queues are valid only once, at the beginning of your login period.
If you make changes to this file and want to apply the configuration directly, you can do so by running the login shell:
exec zsh --login
This is likely the file you will change more often than not on the grounds that it influences your intelligent or interactive shells. It’s frequently utilized for things, for example,
- Key bindings
- Output colors
- Shell command history
- Setting the $PATH variable
Similar to .zprofile read at login, but extracted from .zshrc if not logged in to the shell but also interactive.
As the name suggests, it is called loggin out within the login shell. Can be used to clean the terminal.
To fix the problem on Linux, add this line to $HOME/.zshrc where $YOUR_FLUTTER_DIR is the directory where you downloaded Flutter:
If you work e. g. use bash to install it individually (.bashrc) instead.
MacOS (Catalina and newer)
MacOS behaves like a Linux distribution. However, there is a small difference. Let’s examine them by looking at the order of execution:
Same way of behaving as a Linux pendant.
Basically a similar way of behaving as the Linux pendant. In any case, there is a slight distinction in /etc/zprofile:
Which is the system-wide equivalent of the .zprofile of the user.
Its content is as follows:
1. # System environment profile for zsh(1) login shell. 2. 3. # Configure the user interface for this in ~/.zprofile. See zshbuiltins(1) 4. # in zshoptions(1) for details. 5. 6. if [-x /usr/libexec/path_helper]; then 7. eval `/usr/libexec/path_helper -s` 8. fi
Now, what is path_helper? Well, let the man give us the answer:
The path_helper utility reads the contents of the files in the /etc/paths.d and /etc/manpaths.d directories and adds their contents to the PATH and MANPATH environment variables respectively. - man page of path_helper
So apparently this program combines the contents of /etc/paths.d and /etc/manpaths.d which in my case only contains /Library/Apple/usr/bin.
Basically, it fits into a Linux pendant.
This provides zsh support for MacOS applications.
Same behavior as the Linux pendant.
This is an explanation of the above explanation. The rows in the table represent the order of execution.
|System-Wide||User||Login Shell||Interactive Shell||Scripts|
The system lists files that apply to all users, and user files that only apply to the current user.
The preview also explains which files are key when opening a login shell, an interactive shell, or before running a script:
As in Linux, add this line to $HOME/.zshrc where $YOUR_FLUTTER_DIR is the directory where you downloaded Flutter:
Debugging the $PATH
If you want to know what is currently in your $PATH variable, you can print its value.
Windows: echo %PATH%
Linux and MacOS: echo $PATH
Putting it all together
Command not found: flutter has a simple reason: flutter as a binary is not in the registry where your operating system is looking for it.
For this to work, you need to add the location of your flutter binary to your system $PATH variable. On Windows, you can do this through the GUI or CLI.
On Linux and MacOS, install or update
export PATH = "$YOUR_FLUTTER_DIR/bin:$PATH"
in your .zshrc or .bashrc.
If you do not know that you are editing a hidden text file: just enter nano ~/.zshrc, edit the line, and press CTRL + X to close and Y to replace. Restore the file by clicking the source ~/.zshrc.