Flutter Version Management
Flutter version management or (FVM) is a tool to manage Flutter SDK Version on your machine. This means that we can define specific Flutter version for different projects.
This tool allows you to manage multiple channels and releases, and caches these versions locally, so you don’t have to wait for a full setup every time you want to switch versions.
1. Install FVM on your machine
- First make sure flutter is already installed. Moreover, it must be flutter stable channel. In your command line just simply type this:
// set flutter to stable channel
flutter channel stable// check flutter channel
flutter channel// output
Flutter channels:
master
dev
beta
* stable
- Once you have determined your flutter is already installed, Let install FVM by the following command:
flutter pub global activate fvm
- There is a warning message at the end of the installation process. So the next step would be to add
fvm path
to our shell’s config file (.bashrc
,bash_profile
, etc.). In order for thefvm
command to work, it is necessary that you have three following lines defined within the file:
export PATH=”$PATH:`pwd`/flutter/bin”
export PATH=”$PATH:`pwd`/bin/cache/dart-sdk/bin”
export PATH=”$PATH:`pwd`/.pub-cache/bin”
- Type
fvm
in your command line to see all available options:
2. Install Flutter SDK Version with FVM
- Type
fvm install stable
to install stable channel. - If you want to see all flutter SDK version releases that you can install just type
fvm releases
- If you want to install specific version. Let say you want to install flutter SDK version 2.05 just type
fvm install 2.0.5
- To see your installed versions. just type:
fvm list
3. Use FVM in your project
- In your root file of your project type
fvm use <your version>
For example I use 2.0.5. just type fvm use 2.0.5
to see if it is already used that version in your project. Execute this fvm list
command:
4. Set up to your IDE
Let configure your IDE. In my example, I will show you how to finish the setup process in VS code.
- After using the above commands to use your flutter SDK version. You will see
.fvm
folder in your root file.
- Press
cmd + ,
then go to user setting.json and paste this:
"dart.flutterSdkPaths": ["$YOUR_PATH/fvm/versions",],
- To get the above path simply execute
fvm list
command. Then will show this:
// copy this path
Versions path: $YOUR_PATH/fvm/versions
- To use it please type
cmd + shift + p
and typechange sdk
and then you can choose your prefer version.
- In this example I choose Flutter SDK 2.0.5
5. How Run or Install library in your project
From now on, every commands want to use like flutter run
, flutter pub get
, etc. You MUST prefix them by fvm
.
For example:
// to run your project
fvm flutter run// to install libs
fvm flutter pub get
Conclusion
Flutter Version Management or (FVM) is simple cli to manage Flutter SDK versions.
FVM helps with the need for a consistent app builds by allowing to reference Flutter SDK version used on a per-project basis. It also allows you to have multiple Flutter versions installed to quickly validate and test upcoming Flutter releases with your apps, without waiting for Flutter installation every time.