如何同时安装两个Flutter版本(如稳定版/Beta版或2.0.0/1.22.6)并实现快速切换?
Great question! Managing multiple Flutter versions and switching between them quickly is a total lifesaver—whether you’re maintaining an older project that relies on a specific version or testing out new beta features without breaking your stable workflow. Here are the most practical, low-fuss methods I’ve used over the years:
Method 1: Use FVM (Flutter Version Manager)
This is hands down the easiest and most popular way to handle multiple Flutter versions. It’s a community-built tool designed specifically for this use case, and it lets you manage global and project-specific versions seamlessly.
Install FVM:
On Mac/Linux, use Homebrew:brew install fvm
On Windows, use Chocolatey:choco install fvm
(Package managers are the simplest route, but you can also grab the binary directly from the official FVM repo if needed.)Install your desired versions:
Run these commands to add the versions you need:fvm install stablefvm install betafvm install 2.0.0(for specific older versions)Switch versions globally:
To set a default version for all projects, run:fvm use stable(or beta/2.0.0, whichever you want)Project-specific version locks:
The best part? You can lock a project to a specific version so you don’t accidentally use the wrong one. Just navigate to your project folder and run:fvm use 1.22.6 --local
This creates a.fvmrcfile in your project. Now, whenever you run Flutter commands in this folder, FVM automatically uses the specified version.Verify the switch:
Always double-check withflutter --versionto make sure you’re on the right version.
Method 2: Manual Version Management (No Tools Required)
If you prefer not to use a third-party tool, you can manually manage multiple Flutter installations. It’s a bit more hands-on, but it works perfectly.
Download and store separate Flutter versions:
Head to Flutter’s official releases page, download the ZIP files for the versions you need, and extract each into a distinct folder, like:~/flutter-stable(for stable builds)~/flutter-beta(for beta builds)~/flutter-2.0.0(for the specific 2.0.0 version)
Create shortcuts/aliases to switch quickly:
Mac/Linux: Open your shell config file (
~/.bashrc,~/.zshrc, etc.) and add these aliases:alias flutter-stable='export PATH="$HOME/flutter-stable/bin:$PATH"' alias flutter-beta='export PATH="$HOME/flutter-beta/bin:$PATH"' alias flutter-2.0.0='export PATH="$HOME/flutter-2.0.0/bin:$PATH"'Save the file, then run
source ~/.zshrc(or your config file) to apply changes. Now you just typeflutter-stablein your terminal to switch to that version, then verify withflutter --version.Windows: Create batch files (
.bat) for each version. For example,flutter-stable.batwould contain:@echo off set PATH=C:\flutter-stable\bin;%PATH% cmdDouble-click the batch file to open a terminal with that Flutter version active.
Pro tip: If you want to switch versions permanently until you change it, just update your system’s
PATHenvironment variable to point to the desired Flutterbinfolder.
Bonus Tips
- When switching versions, it’s a good idea to run
flutter cleanandflutter pub getin your project to avoid dependency conflicts. - For CI/CD pipelines, FVM works great too—you can specify the version in your pipeline config to ensure consistent builds.
Hope these methods make switching Flutter versions a breeze! If you hit any snags during setup, feel free to ask for more details.
内容的提问来源于stack exchange,提问作者Abdelrahman Tareq

