Skip to content

Instantly share code, notes, and snippets.

@hkboujrida
Last active March 31, 2024 17:55
Show Gist options
  • Save hkboujrida/34b82c56627b15288911ff6b8c511c41 to your computer and use it in GitHub Desktop.
Save hkboujrida/34b82c56627b15288911ff6b8c511c41 to your computer and use it in GitHub Desktop.
custom wsl ubuntu install

Custom install ubuntu wsl2

Benefits:

  • no need to install ubuntu from the store
  • choose the version you want
  • choose the name you want
  • choose the location you want
  • install multiple versions of ubuntu

Install Ubuntu the classic way

wsl --install -d ubuntu

Install Ubuntu the expert way

First, download the Ubuntu rootfs tarball from the Ubuntu Cloud Images website:

https://cloud-images.ubuntu.com/wsl/mantic/current/ubuntu-mantic-wsl-amd64-wsl.rootfs.tar.gz

Then import it into WSL2:

wsl --import <Distribution Name> <Installation Folder> <Ubuntu WSL2 Image Tarball path>
wsl --import ubuntu-2 D:\Workspaces\wsl\ubuntu2 D:\Workspaces\wsl\ubuntu-mantic-wsl-amd64-wsl.rootfs.tar.gz

add default user (instead of root)

Launch ubuntu-2

wsl -d ubuntu-2

Inside ubuntu-2

NEW_USER=dotexec
useradd -m -G sudo -s /bin/bash "$NEW_USER"
passwd "$NEW_USER"

tee /etc/wsl.conf <<_EOF
[user]
default=${NEW_USER}
_EOF

shutdown ubuntu-2 to apply the changes

wsl --shutdown ubuntu-2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment