# 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: ```sh 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: ```sh 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. ```sh mkdir -p $HOME/Downloads && cd "$_" ``` 2. Download the latest stable [release](https://docs.flutter.dev/development/tools/sdk/releases?tab=linux) of the Flutter SDK _(Right-click and select “Copy link” to copy the address of the archive.):_ ```sh wget https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.7.9-stable.tar.xz ``` 3. Create an `Applications` directory if it doesn’t already exist, and navigate to it. ```sh mkdir -p $HOME/Applications && cd "$_" ``` 4. Extract the Flutter files from the archive in the `Downloads` directory to the `Applications` directory. ```sh 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): ```sh 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 ```sh flutter doctor --android-licenses ``` ## References - [Set up a WSL development environment](https://learn.microsoft.com/en-us/windows/wsl/setup/environment) - [Linux install | Flutter](https://docs.flutter.dev/get-started/install/linux) - [Install Google Chrome for Linux](https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps#install-google-chrome-for-linux) - [Installing Flutter on WSL2 — Windows 10](https://joshkautz.medium.com/installing-flutter-2-0-on-wsl2-2fbf0a354c78) - [Installing Android Studio on WSL2 for Flutter](https://addshore.com/2022/01/installing-android-studio-on-wsl2-for-flutter/)