Skip to content

Instantly share code, notes, and snippets.

Last active November 20, 2021 20:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save amnuts/fa3c96015e52c855ecf028030b36c5d6 to your computer and use it in GitHub Desktop.
setting up WSL2

These are just some notes on my setting up of WSL

    I wanted to run WSL and the WSL docker containers from a location that wasn't my C drive, and this explains how
    Excluding WSL files from Windows Defender apparently helps to increase speed
    General commands to set things up that I wanted

In PowerShell terminal, go to desired location. Eg, G:

wsl -l to see distros, eg:

Ubuntu-20.04 (Default)


wsl --export Ubuntu-20.04 ubuntu.tar
wsl --export docker-desktop-data docker-desktop-data.tar
wsl --export docker-desktop docker-desktop

That will create the backups files. When you're happy that the files are there and have some size, it's time to get rid of them from the original location (typically C drive):

wsl --unregister Ubuntu-20.04
wsl --unregister docker-desktop-data
wsl --unregister docker-desktop

When done, it's time to import them to the new location. For example, G:/wsl and G:/docker:

wsl --import Ubuntu-20.04 G:\wsl\Ubuntu-20.04\ .\ubuntu.tar --version 2
wsl --import docker-desktop-data G:\docker\docker-desktop-data\ .\docker-desktop-data.tar --version 2
wsl --import docker-desktop G:\docker\docker-desktop\ .\docker-desktop.tar --version 2

Once installed and happy of the new locations, the .tar files can be removed.

You may need to reset the default user for the ubuntu distribution (due to a current export/import bug). That can be done by using the distro's config command in PowerShell and substituting <username> for the actual username you want to make default.

ubuntu2004 config --default-user <username>

Copy the PowerShell file listed at to a file on your computer, eg excludeWSL.ps1.

You may need to adjust the policy of the machine to allow you to run the script.

Check the policy with a PowerShell terminal started with Administrator:

Get-ExecutionPolicy -List

That might show something like:

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine      Restricted

If it's Restricted and not RemoteSigned then change that with:

Set-ExecutionPolicy RemoteSigned

and answer Y (yes) or A (all) to the question it asks.

Now run the script with:


(or whatever you named the script)

General installation of stuff

sudo apt update
sudo apt upgrade
sudo apt install -y python-is-python3 pipenv
sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common unzip
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install -y php8.0 php8.0-cli php8.0-common php8.0-xml php8.0-zip php8.0-mbstring php8.0-phpdbg php8.0-intl php8.0-mbstring php8.0-mysql php8.0-curl php8.0-dev php8.0-xdebug php8.0-ast php8.0-sqlite3 php8.0-opcache php8.0-msgpack
sudo apt install -y nodejs npm
curl -sS | sudo apt-key add -
echo "deb stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install yarn
curl -o- | bash
source ~/.bashrc
nvm install --lts

Setting up of zsh and oh-my-zsh

Get any fonts from (I like the JetBrains Mono) and install into the Windows fonts. Set the terminal (I'm using the Windows Terminal Preview) to use the font you want in the settings

I'm also using powerlevel10k theme for oh-my-zsh.

sudo apt install -y zsh
chsh -s /bin/zsh
sh -c "$(curl -fsSL"
git clone --depth=1 ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

I wanted Python 3.9, so...

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.9
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 3
sudo update-alternatives --config python

Then enter the selection number required (in my instance, it was 3 - Python 3.9).

Now set up aws cli:

curl "" -o ""
sudo ./aws/install
rm -rf aws
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment