How To Run Multiple Flutter Versions on macOS

Written by altynberg | Published 2021/06/17
Tech Story Tags: flutter | flutter-tutorial | flutter-app-development | flutter-for-mobile-app | mobile-programming-flutter | flutter-app | visual-studio-code

TLDRvia the TL;DR App

Sometimes we need to have multiple Flutter versions on the same machine for different projects. To do this, we should download multiple versions and add those paths to the bash_profile file and our IDE. I will use macOS and Visual Studio Code.
I assume that Flutter is already installed. So we should already have a Flutter SDK folder. Let's download a different version of Flutter and place it in the same folder as the current SDK folder.
In my case, as a default, I had an older version of Flutter. In addition to that, I downloaded the stable channel and renamed it
flutter_stable
. Now I have two versions in two different paths:
Next, we duplicate the
flutter_stable/bin/
flutter
file and rename it to
flutter_stable/bin/
flutterstable
. Actually, we can give it any name. We will use this name instead of the
flutter
command, like
flutterstable --version
.
Now execute
nano ~/.bash_profile
or
nano ~/.zshrc
depending on the shell and add the path of the new version. In my case, it looks like this (I added the second row):
export PATH="$PATH:/Users/user/flutter/bin"
export PATH="$PATH:/Users/user/flutter_stable/bin"
Save, exit, and restart the terminal.
Verify if the path is correct with the command
which flutterstable
. It must give something like this:
/Users/user/flutter_stable/bin/flutterstable
.
Now the
flutterstable --version
and
flutter --version
commands should give different versions.

Visual Studio Code

Every project can use a specific version of Flutter. Open the settings of Visual Studio Code (
Cmd+,
) and search 'flutter sdk paths'. Select the 'Dart & Flutter' in the left menu, click 'Add item', and add the paths. In my case the result looks like this:
Restart Visual Studio Code.
Now, you can select the Flutter version using
cmd+shift+p
--> "
Flutter: Change SDK
". After selecting the Flutter SDK, the value of "
dart.flutterSdkPath
" in
.vscode/settings.json
should be changed to the path of the selected Flutter SDK.
As a result, we have two different versions of Flutter and we can use different versions for different projects.

Written by altynberg | Software Engineer
Published by HackerNoon on 2021/06/17