🚀 Flutter FVM Setup and How to Use It in Code

Managing multiple Flutter SDK versions manually can be a headache — especially when you work on multiple projects that require different Flutter versions. That’s where FVM (Flutter Version Management) comes in handy.

In this post, you’ll learn:

  • What FVM is and why you should use it
  • How to install and set up FVM
  • How to use FVM in your Flutter projects
  • How to integrate FVM in your IDE or CI/CD setup

🧠 What is FVM?

FVM stands for Flutter Version Management. It allows you to easily install, manage, and switch between different Flutter SDK versions per project.

Instead of having one global Flutter SDK on your system, FVM keeps multiple versions locally and lets each project use its own version.

✨ Benefits of Using FVM

  • Manage multiple Flutter SDK versions
  • Avoid version conflicts between projects
  • Ensure consistent builds across team members
  • Simplify CI/CD pipelines

⚙️ Step 1: Install FVM

You can install FVM via pub, Homebrew, or Chocolatey (depending on your OS).

macOS or Linux (via pub):

dart pub global activate fvm

Or with Homebrew:

brew tap leoafarias/fvm
brew install fvm

Windows (via Chocolatey):

choco install fvm


🛠 Step 2: Configure Your PATH

After installation, make sure FVM’s bin path is added to your system PATH.

You can check where it’s installed using:

fvm --version

If it works, you’re good to go!


🧩 Step 3: Install a Flutter Version Using FVM

You can install a specific Flutter version (for example, stable or a specific version like 3.22.0):

fvm install stable

or

fvm install 3.22.0

You can list all installed versions:

fvm list

And check available versions:

fvm releases


📂 Step 4: Set Flutter Version for a Project

Inside your Flutter project, run:

fvm use 3.22.0

This will create a .fvm folder in your project containing:

  • A symbolic link to the SDK
  • A configuration file (fvm_config.json)

Now your project is locked to Flutter version 3.22.0, ensuring everyone on your team uses the same SDK.


🚀 Step 5: Running Flutter Commands via FVM

You can run any Flutter command through FVM by prefixing it with fvm flutter.

Example:

fvm flutter pub get
fvm flutter run
fvm flutter build apk

If you want, you can make this easier by adding an alias in your shell:

bash/zsh:

alias flutter="fvm flutter"

Now you can use flutter normally, and it will automatically use the FVM-managed version.


💻 Step 6: Using FVM in VS Code or Android Studio

VS Code

  1. Open Command Palette → “Flutter: Change SDK”
  2. Select the path: .fvm/flutter_sdk

Or add this setting in .vscode/settings.json:

{
  "dart.flutterSdkPath": ".fvm/flutter_sdk"
}

Android Studio

Go to Preferences → Languages & Frameworks → Flutter,
and set the SDK path to your project’s .fvm/flutter_sdk.


⚡ Bonus: Using FVM in CI/CD

In your CI configuration, install FVM, and use it to run Flutter commands consistently across environments.

Example (GitHub Actions):

- name: Install FVM
  run: dart pub global activate fvm

- name: Install Flutter via FVM
  run: fvm install

- name: Get dependencies
  run: fvm flutter pub get

- name: Run tests
  run: fvm flutter test

This ensures your pipeline always uses the exact Flutter version defined by your project.


🧾 Conclusion

FVM makes Flutter development more predictable and consistent across teams and machines.
By using FVM, you can:

  • Pin each project to its own Flutter SDK
  • Simplify environment setup
  • Avoid “works on my machine” problems

Start using FVM today and make your Flutter workflow cleaner, faster, and version-safe.


🧩 Quick Reference Commands

CommandDescription
fvm install <version>Install specific Flutter version
fvm use <version>Use version for current project
fvm listList installed versions
fvm flutter <command>Run Flutter command with FVM version

2 responses to “🚀 Flutter FVM Setup and How to Use It in Code”

  1. 注册 Avatar

Leave a Reply

Your email address will not be published. Required fields are marked *