How to Add Flutter to Your PATH on macOS
To use Flutter commands from the Terminal on macOS, you need to add Flutter to your PATH environment variable. Here’s a step-by-step guide to help you set this up using the default zsh shell.
Step 1: Open Terminal
Launch the Terminal application on your Mac. You can find it in Applications > Utilities or by searching for it using Spotlight.
Step 2: Create or Edit the ~/.zshenv
File
- Check for Existing File: First, check if the
~/.zshenv
file exists:
ls -al ~/.zshenv
If the file does not exist, you’ll need to create it.
2. Create or Edit the File:
Open the file in a text editor. You can use nano
for simplicity:
nano ~/.zshenv
This above command create new .zshenv file
Step 3: Add Flutter to Your PATH
export PATH=$HOME/src/flutter/bin:$PATH
This above line appends the Flutter binary path to your existing PATH variable. Considering i have the flutter folder inside Home
path src
folder
- Save and Exit:
- If you’re using
nano
, save the file by pressingCtrl + O
, then pressEnter
to confirm. Exit by pressingCtrl + X
. - If using
vim
, pressEsc
to enter command mode, type:wq
, and pressEnter
to save and exit.
Step 4: Apply the Changes
To make the changes take effect, you need to refresh your Terminal session. Run the following command:
source ~/.zshenv
Step 5: Verify Flutter Installation
To ensure that Flutter is correctly added to your PATH, run:
flutter --version
This command should display the Flutter version if everything is set up correctly.
