This tutorial shows you how to downgrade or upgrade Flutter SDK version using various methods.
If you install Flutter SDK on your computer, you'll install the latest stable version by default. For some reason, you may want to use an older version. As an example, if the code cannot be run using the latest stable version. On the contrary, sometimes you may want to try new features of a pre-release version. As a result, you need to change the used Flutter SDK version. Previously, Flutter has downgrade
command. Unfortunately, it can't be used anymore in the newer versions. However, there are some alternatives for changing the SDk version which can be found in this tutorial.
Before changing the version, you can check the current version by using the command below.
flutter --version
Upgrade/Downgrade by Changing Flutter Repository Branch
Changing the used Flutter version can be done by changing the git branch to a specific version. First of all, you have to go to the Flutter SDK directory. The location may vary based on the operating system and how you install it. For example, if you installed the SDK using snap on Ubuntu, by default the directory should be /home/username/snap/flutter/common/flutter
. You can use the command below to check the SDK path.
flutter sdk-path
Then, go to the SDK directory using terminal (or you can use git GUI client too). I assume you've installed git on your computer. If you don't have git installed, you need to install it first. By default, you should be on the stable
branch. You can use the git branch
command to see the list of available branches. Each version has its own branch, so you can just checkout to a specific version using git checkout {branchName}
command. For example, to change the version to 1.22.0, you can use the command below.
git checkout 1.22.0
After that, run any Flutter command such as flutter --version
or flutter doctor
which causes Flutter to perform download and compile for the selected version.
Upgrade/Downgrade by Changing Flutter Channel
Flutter has some channels, which can be seen by using flutter channel
command. As for now, the available channels are
master
dev
beta
stable
Each version can have different versions. For example, the stable
channel uses the latest stable version, while the beta
channel uses a pre-release version. To change the channel, you can use flutter channel {channelName}
command. Below is the example for changing the channel to beta
.
flutter channel beta
Just like the previous method, you need to run any Flutter command so that it can download and compile libraries and codes for the version used by the selected channel.
Upgrade/Downgrade by Downloading Specific SDK Version
Another alternative to upgrade or downgrade the Flutter SDK version is by downloading a specific SDK version from the website. Just download a version you want that matches your operating system and extract it to a folder. If the directory is different than the previously used version, you have to change the SDK path of the PATH variable and the IDE that you use.
For updating the PATH variable on Linux, macOS, and Chrome OS, add the export statement below on the $HOME/.bashrc
(Linux/Chrome OS) or $HOME/.zshrc
(macOs) file. If there's already an existing export statement for Flutter, just replace the existing one.
export PATH="$PATH:[PATH_OF_FLUTTER_GIT_DIRECTORY]/bin"
For Windows, open the Edit environment variables for your account GUI window, select User variables and edit the Path entry by appending the full path to the Flutter SDK bin. The Path variable uses ;
as the value separator. If the Path entry doesn't exist, just create a new entry named Path.
Upgrade to The Latest Version
To upgrade the SDK to the latest version, you can run the upgrade
command and just wait until the process finishes.
flutter upgrade
The latest version may differ based on the current channel.
Summary
There are several ways to upgrade or downgrade the Flutter SDK version. It can be done by changing the git branch of the Flutter SDK repository, changing the channel, or downloading a specific version from their website. To upgrade to the latest version, you can use the flutter upgrade
command.