7

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

1
  • What problem are you solving that you'd need two flavors of flutter installed. There really aren't more than a few breaking changes from flutter 1.x to 2.x. Or are you thinking you still have projects that need legacy dart? If so, just remember to set the proper minsdk in pubspec.yaml to 2.12.0 for modern dart, and 2.10.0 for legacy dart. Commented Apr 18, 2021 at 15:33

3 Answers 3

17

FVM (Flutter Version Management)

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

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

Installation

Run the following command:

dart pub global activate fvm

Or, using Homebrew:

brew tap leoafarias/fvm
brew install fvm

Finally, export the FLUTTER_ROOT path to be the FVM's default version, by adding the following in your .zshrc file (which can be found in your home directory):

export FLUTTER_ROOT=$HOME/fvm/default/bin

To confirm that FVM has been successfully installed, run fvm --version on the terminal to see version of the installed one.

Usage

  • Installing the SKDs:

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 the latest version in addition to 3.0.0, you should run the first and second commands (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 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 do I know which version I use for a certain project?"

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

fvm doctor

Or, since you can run the Flutter commands via the used FVM SDK, you could also run

fvm flutter --version

For more information about FVM, check the FVM documentaion.

Sign up to request clarification or add additional context in comments.

3 Comments

Tks! this answer should be marked as the best one, it solve the issue in better way
Just a mention, you wrote brew install nvm. Is that correct or should it be brew install fvm?
Thanks @Daniel. That's correct, it's brew install fvm, updated.
9

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

2 Comments

this option worked for me
Then how to switch from 1 version to another when it needs?
5

Open Terminal & type: echo $SHELL to check what SHELL you're using, If you use ZSHELL, not BASH, just 1 step to do this task (if BASH, please flow content of @Adelina in this topic):

  • Open Terminal and type: nano ~/.zshrc
  • For me, I'm using 2 versions 2.10.5 & 3.7.x, with ver 2.10.5, I don't need to add alias, default is flutter doctor. And with ver 3.7.x, I just add 1 alias "flutter3" like below:
  export PATH="$PATH:/Users/macbookpro/development/flutter/bin"

  export JAVA_HOME=$(/usr/libexec/java_home)

  export PATH="$PATH:/Users/macbookpro/development/flutterV3/bin"

  alias flutter3="/Users/macbookpro/development/flutterV3/bin/flutter"

After add 4 lines above with 2 versions Flutter that you have on Mac, press Ctrl + O, tap Enter to save file ZSHELL, and then press Ctrl + X to close file ZSHELL. Return to Terminal current session, restart Terminal or restart Mac and type flutter3 doctor or flutter doctor to test

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.