Skip to content

Instantly share code, notes, and snippets.

@franTarkenton
Last active May 19, 2026 23:47
Show Gist options
  • Select an option

  • Save franTarkenton/3a290442e13189908a959d942a172db3 to your computer and use it in GitHub Desktop.

Select an option

Save franTarkenton/3a290442e13189908a959d942a172db3 to your computer and use it in GitHub Desktop.
Windows subsystem for linux 2 setup

Intro

Misc help on using WSL:

WSL Version

If like me you maintain your original WSL 1 version, and instead of upgrading you installed a new WSL 2 distribution then you may want to define a default version.

Check WSL Version

wsl -l -v

outputs something like this:

C:\WINDOWS\system32>wsl.exe -l -v
  NAME                   STATE           VERSION
* Ubuntu                 Running         1
  docker-desktop         Running         2
  Ubuntu-20.04           Running         2
  docker-desktop-data    Running         2

The '*' next to Ubuntu indicates that it is the default version, and also if you look at the version column you can see that it is running under WSL version 1. You will also see that I have a version called 'Ubuntu-20.04' That's the version I want to set as the default version.

wsl -s Ubuntu-20.04

and now verify that the default version has been set:

C:\WINDOWS\system32>wsl.exe -l -v
  NAME                   STATE           VERSION
* Ubuntu-20.04           Running         2
  docker-desktop         Running         2
  Ubuntu                 Running         1
  docker-desktop-data    Running         2

reboot wsl

wsl --shutdown

Install Docker

This is almost a complete cut and paste of instructions found (here)[https://blog.avenuecode.com/running-docker-engine-on-wsl-2]:

uninstall old versions:

sudo apt remove docker docker-engine docker.io containerd runc

Install dependencies

sudo apt update && sudo apt upgrade -y
sudo apt remove docker docker-engine docker.io containerd runc
    sudo apt-get install \
        apt-transport-https \
        ca-certificates \
        curl \
        gnupg \
        lsb-release -y

Add Docker repository

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu   $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install docker packages

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io -y

Setup current user to access docker

sudo usermod -aG docker $USER

Install docker-compose

sudo curl -L \
"https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose 
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Test install

# start engine
sudo service docker start
docker run hello-world

Configure docker engine to start automatically

Add the following line to the .bashrc file

...
wsl.exe -u root service docker status || wsl.exe -u root service docker start

Install brew

Following these guidelines

sudo apt-get install build-essential curl file git

Then install linux brew...

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Finally add the homebrew path to the your .profile

echo 'export PATH=/home/linuxbrew/.linuxbrew/bin:$PATH' >>~/.bash_profile

Install brew packages

  • helm
  • act
brew install helm act 

Other useful stuff

Start specific WSL distribution

As show above specific distros can be listed using:

wsl -l

Then to run one, just type its name, example:

Microsoft Windows [Version 10.0.666.666]

KJNETHER@SILLYWINDOWS C:\tools\Cmder
$ wsl -l
Windows Subsystem for Linux Distributions:
Ubuntu-20.04 (Default)
docker-desktop
Ubuntu
docker-desktop-data

KJNETHER@SILLYWINDOWS C:\tools\Cmder
$ Ubuntu

kjnether@SILLYWINDOWS:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.5 LTS
Release:        18.04
Codename:       bionic
kjnether@SILLYWINDOWS:~$

Other packages I install:

  • jq

Dealing with VPN

adapted from

Find the DNS ips that the VPN is using

Powersmell cli to get the dns ips for the vpn: (Get-NetAdapter | Where-Object InterfaceDescription -like "Cisco AnyConnect*" | Get-DnsClientServerAddress).ServerAddresses

Add those to the WSL file: /etc/resolv.conf

example:

...
nameserver <ip goes here>
nameserver <ip goes here>
...

Attempt to ping the host

Firewall Rules - Not sure if this is required, think it may have been with new machine so I can ping the hosts netsh advfirewall firewall add rule name="ICMPv4 Allow Ping Requests" protocol=icmpv4:8,any dir=in action=allow Enable-NetFirewallRule -DisplayName 'Virtual Machine Monitoring (Echo Request - ICMPv6-In)' OLD STUFF...

This link provided these powershell commands that can be run after VPN is connected to give WSL higher level priority.

Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 6000
(Get-NetAdapter | Where-Object InterfaceDescription -like "Cisco AnyConnect*" | Get-DnsClientServerAddress).ServerAddresses

other options:

Shrinking the WSL Drive

For whatever reason you may fill up your WSL hard drive. If your drive is configured to grow based on demand, you may eventually find yourself in the situation where your disk has used up all the space on your machine. In my experience this has happened when running various data pipelines that pull / prep / and push data, but do not necessarily clean up after themselves.

  1. find the path to your WSL ext4.vhdx file, if you are running ubuntu under wsl look for a folder in C:\Users\kjnether\AppData\Local\Packages\ that has the word ubuntu in it... mine is: CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc
  2. open a cmd with admin permissions
  3. shutdown wsl wsl --shutdown
  4. open diskpart diskpart
  5. select the disk, for me this is the command select vdisk file="C:\Users\kjnether\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\ext4.vhdx"
  6. select disk for readonly attach vdisk readonly
  7. compact the disk compact vdisk
  8. detach the disk detach vdisk
  9. yer now done! exit

Install oracle instant client

I'm going to install in /opt/oracle, you can install anywhere you see fit.

prerequisites

sudo apt install libaio1t64
# you also will need this symbolic link
sudo ln -s /usr/lib/x86_64-linux-gnu/libaio.so.1t64 /usr/lib/x86_64-linux-gnu/libaio.so.1

Create the directory:

sudo mkdir /opt/oracle
cd /opt/oracle

Get the software:

sudo wget https://download.oracle.com/otn_software/linux/instantclient/1924000/instantclient-basic-linux.x64-19.24.0.0.0dbru.zip
sudo wget https://download.oracle.com/otn_software/linux/instantclient/1924000/instantclient-sqlplus-linux.x64-19.24.0.0.0dbru.zip

Unpack the software

sudo unzip instantclient-basic-linux.x64-19.24.0.0.0dbru.zip
sudo unzip instantclient-sqlplus-linux.x64-19.24.0.0.0dbru.zip

Modify environment, by opening .bashrc and adding the following lines to the file:

export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_24:$LD_LIBRARY_PATH
export PATH=/opt/oracle/instantclient_19_24:$PATH

Export WSL config - (to transfer WSL to new computer)

Summarized from here

Verify the name of the wsl install

For most the name will be Ubuntu

wsl --list

Export to a flashdrive

The following isn't used, but is rather a backup in case things go sideways

wsl --export Ubuntu D:\wsl_backup\ubuntu.tar

Now export your current wsl image file

wsl --export --vhd <Distribution Name> <FileName>

Importing the export on the new computer

Where "FileName" is the image that was exported in previous steps.

wsl --import-in-place <Distribution Name> <FileName>

Other Misc

Migrate to new machine

network configuration

Started running into issues where vscode wasn't able to authenticate to github for my copilot subscription. Not sure if this going to work, but to try to facilitate the network communication betweek copilot and the auth process adding the github ip to the network configuration:

Open up /etc/network/interfaces, then add the following line to the file:

140.82.121.6 api.github.com

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