Installing Flutter on WSL2 — Windows 10

Josh Kautz
4 min readMay 4, 2021

--

Updated: January 14th, 2022 to use most recent versions of Ubuntu (20.04.3 LTS), Flutter (2.8.1), Dart (2.15.1), and all accompanying screenshots.

Using the Paradox Oh-My-Posh theme with my custom configuration in Windows Terminal.

I’m running Ubuntu 20.04.3 LTS on Windows Subsystem for Linux - WSL2 - and I’ve been enjoying it a lot now that I’m working off a Windows 10 machine. As a former Mac user - I wanted to leverage WSL2 while doing my Flutter development, so here’s how I went about setting up my environment. I will be running all of my commands in Bash, Ubuntu’s default shell.

Install Flutter

Create a Downloads directory if it doesn’t already exist, and navigate to it.

mkdir -p $HOME/Downloads && cd "$_"

Download the latest Flutter SDK release. (Right-click and select “Copy link address” to copy the address of the archive.)

Flutter SDK releases for different platforms and channels.
wget https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_2.8.1-stable.tar.xz

Create an Applications directory if it doesn’t already exist, and navigate to it.

mkdir -p $HOME/Applications && cd "$_"

Extract the Flutter files from the archive in the Downloads directory to the Applications directory.

tar xfv $HOME/Downloads/$(ls -d $HOME/Downloads/flutter*.tar.xz | xargs basename)

Add the Flutter path to the Bash shell PATH variable in$HOME/.bashrc.

echo -e "\n# Flutter\nexport PATH=\$HOME/Applications/flutter/bin:\$PATH" >> $HOME/.bashrc

Execute the source Bash shell command to update the PATH variable in your working session.

source $HOME/.bashrc

Verify that Flutter is installed!

flutter --version
Flutter successfully installed!

Check if there are any dependencies you need to install to complete the setup.

flutter doctor

The flutter doctor command checks your environment and displays a report to the terminal window. While we do have flutter properly installed, it is missing some dependencies that we’ll need.

Flutter relies on a full installation of Android SDK to supply its Android platform dependencies. So next we’ll install Android SDK.

Install Android SDK

Install the unzip utility and the default-jdk development utility

sudo apt install unzip default-jdk -y

Create a Downloads directory if it doesn’t already exist, and navigate to it.

mkdir -p $HOME/Downloads && cd "$_"

Download the latest Android SDK Command line tools for Linux. (Right-click the download button and select “Copy link address” to copy the address of the archive.)

Latest releases of Android SDK Command-Line Tools for different platforms.
wget https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip

Create an Applications directory if it doesn’t already exist, and navigate to it.

mkdir -p $HOME/Applications && cd "$_"

Extract the Android SDK Command line tools files from the archive in the Downloads directory to the Applications directory.

unzip $HOME/Downloads/$(ls -d $HOME/Downloads/commandlinetools-linux*.zip | xargs basename) -d ./android

Get thesdkmanagerversion. (As of writing, 5.0 is the latest stable release.)

version=$($HOME/Applications/android/cmdline-tools/bin/sdkmanager --sdk_root=$HOME/Applications/android --version | head -n1);
echo $version;

Create a new version directory for the command line tools.

mkdir -p $HOME/Applications/android/cmdline-tools/$version

Move the command line tools to the new version directory.

mv -vt $HOME/Applications/android/cmdline-tools/$version/ $HOME/Applications/android/cmdline-tools/!($version)

Add the cmdline-tools path to the Bash shell PATH variable in$HOME/.bashrc. This allows us to easily use tools like sdkmanager.

echo -e "\n# Android\nexport PATH=\$HOME/Applications/android/cmdline-tools/$version/bin:\$PATH" >> $HOME/.bashrc;

Execute the source Bash shell command to update the PATH variable in your working session.

source $HOME/.bashrc

Install packages with sdkmanager.

sdkmanager --install "system-images;android-31;google_apis;x86_64" "platform-tools" "platforms;android-31" "build-tools;31.0.0" "cmdline-tools;latest"

List all the successfully install packages

sdkmanager --list_installed
Packages successfully installed via sdkmanager!

Add the newly installed platform-tools and emulator path to the Bash shell PATH variable in$HOME/.bashrc. This gives us access to tools like adb, which we’ll need later when we use Android Emulators for running our Flutter apps.

echo -e "export PATH=\$HOME/Applications/android/emulator:\$PATH" >> $HOME/.bashrc;
echo -e "export PATH=\$HOME/Applications/android/platform-tools:\$PATH" >> $HOME/.bashrc;

Execute the source Bash shell command to update the PATH variable in your working session.

source $HOME/.bashrc

Configure Flutter

Configure flutter to use the Android SDK.

flutter config --android-sdk $HOME/Applications/android/

Accept Android SDK licenses.

sdkmanager --licenses

Check to see if if there are any more dependencies that you’ll need to install to complete the setup.

flutter doctor
The Android SDK dependency is all set up and ready to go!

Nice work! We’ve now got Flutter and the Android SDK all set up on WSL2!
But, see that message — “No devices available” — in the screenshot above? We need to fix that. Next, we’ll be setting up our devices for development and debugging, but that deserves its own posts…

--

--

Josh Kautz
Josh Kautz

Written by Josh Kautz

DevOps Software Engineer II at C.H. Robinson

Responses (14)