Share
Explore

Installing FVM for Flutter and Setting the Default Environment on macOS, Windows, and Linux

Introduction
Flutter Version Management (FVM) is a simple tool to manage Flutter SDK versions per project. It allows you to install and manage multiple versions of the Flutter SDK, making it easier to switch between different projects that require different versions. This guide will walk you through the steps to install FVM and set the default Flutter environment on macOS, Windows, and Linux.

Prerequisites

Flutter SDK: Ensure that you have Flutter installed on your system.
Dart SDK: FVM requires Dart. If you have Flutter installed, Dart comes bundled with it.
Command-Line Tools: Basic knowledge of using the terminal or command prompt.

Installation on macOS

Method 1: Using Homebrew (Recommended)
Step 1: Install Homebrew (if not already installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 2: Install FVM
brew tap leoafarias/fvm
brew install fvm
Method 2: Using Dart Pub
Step 1: Activate FVM
dart pub global activate fvm
Step 2: Add FVM to PATH
Add the following line to your shell profile (~/.bashrc, ~/.zshrc, or ~/.bash_profile):
export PATH="$PATH":"$HOME/.pub-cache/bin"
Then, reload your shell:
source ~/.zshrc

Installation on Windows

Method 1: Using Chocolatey (Recommended)
Step 1: Install Chocolatey (if not already installed)
Run the following command in an elevated Command Prompt or PowerShell:

Set-ExecutionPolicy Bypass -Scope Process -Force; `
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; `
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Step 2: Install FVM
choco install fvm
Method 2: Using Dart Pub
Step 1: Activate FVM
dart pub global activate fvm
Step 2: Add FVM to PATH
Add the following path to your system environment variables:
%USERPROFILE%\AppData\Local\Pub\Cache\bin

Installation on Linux

Method 1: Using APT (For Debian/Ubuntu)
Step 1: Add the FVM APT Repository
echo "deb [trusted=yes] https://apt.fvm.app stable main" | sudo tee /etc/apt/sources.list.d/fvm.list
Step 2: Update and Install FVM
sudo apt update
sudo apt install fvm
Method 2: Using Snap
Step 1: Install FVM
sudo snap install fvm
Method 3: Using Dart Pub
Step 1: Activate FVM
dart pub global activate fvm
Step 2: Add FVM to PATH
Add the following line to your shell profile (~/.bashrc or ~/.zshrc):
export PATH="$PATH":"$HOME/.pub-cache/bin"
Then, reload your shell:
source ~/.bashrc
Setting the Default Flutter Version
After installing FVM, you can manage Flutter SDK versions and set a default version.
Step 1: List Available Flutter Versions
fvm releases
Step 2: Install a Specific Flutter Version
Replace stable with the desired version (e.g., 3.3.10).
fvm install stable
Step 3: Set the Global Flutter Version
fvm global stable
Step 4: Verify the Default Flutter Version
flutter --version
You should see that Flutter is now using the version you set globally with FVM.
Note: Ensure that the Flutter command is pointing to FVM. If not, you may need to adjust your PATH or use the FVM Flutter wrapper.

Optional: Use FVM Flutter Wrapper
To ensure you’re always using the FVM-managed Flutter, you can alias the Flutter command.
On macOS and Linux:
Add to your shell profile:
alias flutter="fvm flutter"
Then, reload your shell:
source ~/.bashrc
On Windows:
Use the following command in PowerShell:
function flutter { fvm flutter $args }
To make it permanent, add the function to your PowerShell profile script.
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.