Skip to content

Instantly share code, notes, and snippets.

@JoshuaWierenga
Last active January 19, 2022 12:23
Show Gist options
  • Save JoshuaWierenga/94eb0eadf94ba35d6f6b2e9569821f2b to your computer and use it in GitHub Desktop.
Save JoshuaWierenga/94eb0eadf94ba35d6f6b2e9569821f2b to your computer and use it in GitHub Desktop.
Script to setup ubuntu wsl2 for flutter linux application development
#!/bin/bash
# There are some potential problems with this as previously I needed to install a never version of mesa from ppa:oibaf/graphics-drivers
# for flutter apps to work as otherwise only a white window would appear with various opengl related errors in the console.
# This may have been fixed by switching from gwsl to regular vcxsrv to ensure -nowgl was used and -wgl wasn't.
# Additionally it would be useful to work around cmake issues during the session this runs in by remounting the windows partition rather than
# forcing a wsl2 restart.
# Would also be nice to clean up the console output, for example hiding tee's(or cat's?) output.
# To run use
# wget https://gist.githubusercontent.com/JoshuaWierenga/94eb0eadf94ba35d6f6b2e9569821f2b/raw/setupflutterlinux.sh && chmod +x setupflutterlinux.sh && ./setupflutterlinux.sh && rm setupflutterlinux.sh
# ensure everything is updated
sudo apt update
sudo apt upgrade -y
# install everything required by flutter for linux desktop applications
sudo apt install -y zip unzip clang cmake ninja-build pkg-config libgtk-3-dev
# fix cmake configuration bug on wsl2 if flutter project is on a windows partition
cat << EOF | sudo tee /etc/wsl.conf
# /etc/wsl.conf
[automount]
options = "metadata"
enabled = true
EOF
# setup wsl2 for remote windows xserver and add flutter to path
{
echo export DISPLAY='$(cat /etc/resolv.conf | grep nameserver | awk '\''{print $2; exit;}'\'')':0.0
echo export PULSE_SERVER=tcp:'$(cat /etc/resolv.conf | grep nameserver | awk '\''{print $2; exit;}'\'')'
echo PATH='"$PATH:$(pwd)/flutter/bin"'
} >> ~/.bashrc
source ~/.bashrc
# install flutter to home directory and configure for linux desktop applications
cd ~ && git clone https://github.com/flutter/flutter.git -b beta
flutter config --no-analytics --no-enable-android --no-enable-web --enable-linux-desktop && flutter precache
# alert user to cmake issues and current solution given above config changes
read -n1 -s -r -p $'If flutter development will occur on a windows partition, restart wsl using wsl.exe --shutdown or wsl.exe -t {name of container} to avoid cmake errors.\nPress any key to continue.\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment