How to add path variable in MacOS for flutter

If you’re diving into Flutter development on macOS, setting up your environment correctly is crucial. I’ve been through this process and want to share some insights on how you can get Flutter commands up and running smoothly from your macOS Terminal. This involves tweaking the PATH variable, which might sound technical, but I’ll guide you through it.

Temporary PATH Variable Setup

Firstly, let’s talk about a quick, temporary setup. This is handy if you’re experimenting or don’t want to make permanent changes. Open your Terminal app (yes, the same one you use for other Mac commands) or the integrated Terminal in Visual Studio Code. Then, you’ll want to type in this command:

export PATH=$HOME/[PATH TO FLUTTER SDK]/flutter/bin:$PATH

Replace [PATH TO FLUTTER SDK] with the path where you’ve installed the Flutter SDK. This step is like telling your system, ‘Hey, here’s where Flutter lives; let’s use it from here for now.’

Permanent PATH Variable Setup

For a more long-term solution, especially if you’re committed to Flutter development, setting the PATH variable permanently is the way to go. This is particularly relevant if you’re using macOS Catalina or newer versions. Here’s how to make it stick:

  1. Open your Terminal App (the trusty command center of macOS).
  2. Type touch ~/.zshrc and press Enter. This command gets you a file where you can set environment variables.
  3. Now, open this file by typing vi ~/.zshrc. If you prefer another text editor, feel free to use that.
  4. Time to add the Flutter path. Type in export PATH=$HOME/[PATH TO FLUTTER SDK]/flutter/bin:$PATH. Remember to replace [PATH TO FLUTTER SDK] with your actual Flutter SDK path.
  5. Save your changes. In vi, you’d do this by hitting :wq.
  6. Lastly, reload the changes with source ~/.zshrc.

Once you’ve done this, all the Flutter commands should be at your fingertips, accessible from the Terminal. It’s like giving your macOS a permanent reminder of where to find Flutter tools.

By following these steps, you’ll set yourself up for a smoother Flutter development experience on your macOS. Remember, it’s all about making sure your system knows where to look for Flutter, whether it’s for a quick session or for your long-term development journey.

References:

  1. Flutter Docs