Skip to content

Instantly share code, notes, and snippets.

@hoainamcse
Last active October 17, 2024 00:57
Show Gist options
  • Save hoainamcse/ea5a8c48e3adf237ea09346df03d0845 to your computer and use it in GitHub Desktop.
Save hoainamcse/ea5a8c48e3adf237ea09346df03d0845 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

@itsjay83
Copy link

itsjay83 commented Mar 6, 2024

thank you namnguyen02!!

@pawanmsr
Copy link

pawanmsr commented Apr 4, 2024

Thank you 🙏. Although, I think you should put Update your path before Run flutter doctor.

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