Skip to content

Instantly share code, notes, and snippets.

@chrisgate
Forked from namnguyen02/flutter-app-in-wsl2.md
Created February 5, 2024 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisgate/6df6766ac1358af74cff726d7ac42a3c to your computer and use it in GitHub Desktop.
Save chrisgate/6df6766ac1358af74cff726d7ac42a3c to your computer and use it in GitHub Desktop.

Build a flutter app in WSL2

Install, build and debug a flutter app in WSL2 (Windows Subsystem for Linux).

Linux setup

Install Java

To install the JDK, execute the following command, which will also install the JRE:

sudo apt install default-jdk

Add the following two lines to /etc/profile (setting the JAVA_HOME environment variable):

export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
export PATH="$JAVA_HOME/bin:$PATH"

Open a new terminal window to automatically source the file.

Install Linux toolchain

For Linux desktop development, you need the following in addition to the Flutter SDK:

sudo apt install clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev

Install Google Chrome (if needed)

Refer to Microsoft's instructions below.

Install Flutter

Install Flutter manually

  1. Create a Downloads directory if it doesn’t already exist, and navigate to it.
mkdir -p $HOME/Downloads && cd "$_"
  1. Download the latest stable release of the Flutter SDK (Right-click and select “Copy link” to copy the address of the archive.):
wget https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.7.9-stable.tar.xz
  1. Create an Applications directory if it doesn’t already exist, and navigate to it.
mkdir -p $HOME/Applications && cd "$_"
  1. 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)

Run flutter doctor

Run the following command to see if there are any dependencies you need to install to complete the setup (for verbose output, add the -v flag):

flutter doctor

Update your path

Add the following line to .bashrc:

export PATH="$HOME/Applications/flutter/bin:$PATH"

Open a new terminal window to automatically source the file (or run source .bashrc)

Install Android Studio

Agree to Android Licenses

flutter doctor --android-licenses

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment