How to setup multiple flutter versions on mac?

Viewed 2181

I want to install both flutter v1.22.6 and v2.0.5 on my mac.

currently I have v1.22.6 set up on my mac and have path for it set aswell.

I want a setup where if I enter the command flutter doctor that corresponds to v1.22.6 and when I enter the command flutter2 doctor that corresponds to v2.0.5

enter image description here

I am new to the terminal can someone please help? as of now flutter doctor corresponds to v1.22.6 only. I tried setting a path for flutter2 but that shows as no command found

enter image description here

2 Answers

You need to create alias

  1. Navigate to your home directory:

    cd ~

  2. Open up .bash_profile using vi:

    vi .bash_profile or vim .bash_profile

  3. Add an alias (press i):

    alias flutter2="~/place_of_folder/flutter2/bin/flutter"

  4. Save the file (press Escape, type :wq, and hit Enter)

  5. Restart Terminal

FVM (Flutter Version Management)

Using the FVM (Flutter Version Management) would be the optimal solution.

Briefly, FVM is an open-source dependency management tool that helps with referencing a certain Flutter SDK version to be used for a certain project, i.e each project can use a different Flutter SDK version.

Installation

Run the command following line:

dart pub global activate fvm

Or, using Homebrew:

brew tap leoafarias/fvm
brew install fvm

Usage

  • Installing the SKDs:

Basically, you install the latest stable Flutter version by running the following command:

fvm install stable

Or, you could specify the version, as:

fvm install [version_number]

For instance, if you want to have the latest version in addition to 3.0.0, you should run the first command and the second command (as fvm install 3.0.0).

  • Using SDK for a project:

In the terminal, change the directory to your project, and run the following command:

fvm use stable

stable could be replaced with a specified SDK version. At this point, each project will have its own Flutter SDK based on the used fvm use version number.

However, you could also use the same version for all of your projects by running the following command:

fvm global stable
  • "How to know which version that I'm using for a certain project?"

In the terminal, change the directory to your project, and run the following command:

fvm doctor

Or, since you are able to run the Flutter commands via the used fvm SDK, you could also run

fvm flutter --version

For more information, you could check the FVM documentaion.

Related