> For the complete documentation index, see [llms.txt](https://wong-coupon.gitbook.io/flutter/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wong-coupon.gitbook.io/flutter/easy-code/fvm.md).

# FVM

When we build Flutter projects in a team, using different Flutter versions can create hard bugs.\
So I use **FVM (**[**Flutter Version Management**](https://fvm.app/)**)** to fix one Flutter version for the project.

My goals are simple:

* New teammates can set up quickly.
* The whole team uses the same Flutter version.
* We can upgrade or downgrade version when needed.

## Install FVM

Official doc: [Installation](https://fvm.app/documentation/getting-started/installation/)

Run:

```bash
dart pub global activate fvm
```

Check:

```bash
fvm --version
```

## Fix Flutter version for the project

You can use one of these two ways.

### Way 1: Use command

Official doc: [Commands Reference](https://fvm.app/documentation/guides/basic-commands/)

```bash
fvm use 3.27.4
```

### Way 2: Set version in config file

Official doc: [Configuration](https://fvm.app/documentation/getting-started/configuration/)

Create or update:

```
.fvm/fvm_config.json
```

Content:

```json
{
  "flutterSdkVersion": "3.27.4"
}
```

After this, the project will follow the exact version you set.

## Add to `.gitignore`

Official doc: [Configuration - Git Ignore](https://fvm.app/documentation/getting-started/configuration/#git-ignore)

To avoid committing cache files, add:

```gitignore
# FVM
.fvm/flutter_sdk
.fvm/bin/cache
.fvm/versions
.fvm_cache/
```

## Use FVM in daily Flutter commands

Official doc: [Running Flutter](https://fvm.app/documentation/guides/running-flutter/)

After setup, I always add `fvm` before Flutter commands:

```bash
fvm flutter pub get
fvm flutter analyze
fvm flutter test
fvm flutter run
fvm dart --version
```

This makes sure every command runs with the fixed Flutter version.

## Setup flow for new teammates

When someone new joins the team, I share this short checklist:

1. `dart pub global activate fvm`
2. `fvm use 3.27.4`
3. `fvm flutter pub get`
4. `fvm flutter run`

With this flow, new teammates do not need to guess Flutter version.

## Combine FVM with Make for shorter and safer commands

When the project grows, terminal commands become longer.\
So I combine FVM with Make to group many steps into one short command.

### Step 1: Create a `Makefile` in project root

Example `Makefile`:

```makefile
FVM := fvm
FVM_CACHE_PATH := $(CURDIR)/.fvm_cache
FVM_ENV := FVM_CACHE_PATH=$(FVM_CACHE_PATH) FLUTTER_SUPPRESS_ANALYTICS=true DART_SUPPRESS_ANALYTICS=true

.PHONY: init
init:
	$(FVM_ENV) $(FVM) install 3.27.4
	$(FVM_ENV) $(FVM) use 3.27.4 --force
	$(FVM_ENV) $(FVM) flutter pub get
```

### Step 2: Run one command

```bash
make init
```

Without Make, most people need to type:

```bash
fvm install 3.27.4
fvm use 3.27.4 --force
fvm flutter pub get
```

Result: from 3 lines to 1 line, easier to remember, easier to teach new teammates, and less chance to miss a step.

If you want full details about grouping commands with Make, check this article:

{% content-ref url="/pages/PG14RfyD6nuNYL68vG7H" %}
[Make](/flutter/easy-code/make.md)
{% endcontent-ref %}

## Update + FVM - Version management

Official doc: [Commands Reference](https://fvm.app/documentation/guides/basic-commands/) | [Common Workflows](https://fvm.app/documentation/guides/workflows/) | [Release In Multiple Channels](https://fvm.app/documentation/advanced/release-multiple-channels)

When you need a new Flutter version, update with:

```bash
fvm use 3.29.0
```

Or edit `.fvm/fvm_config.json`, then run again:

```bash
fvm flutter pub get
```

[Buy Me a Coffee](https://buymeacoffee.com/ducmng12g) | [Support Me on Ko-fi](https://ko-fi.com/I2I81AEJG8)
