Skip to content

Setting up WSL2 from scratch to install ubuntu-22 or any other spefic version of ubuntu to run within windows with all it's gui features (most of).

License

Notifications You must be signed in to change notification settings

ab31mohit/wsl2_setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Setting up WSL2 on Windows 11

This repository demonstrates how to setup wsl2 (Windows Subsystem of Linux 2) for using Ubuntu-22.04 LTS winthin windows.

GitHub repo size

1. Pre-requisites :

  • Go to search & type 'Turn windows features on or off' & select the following checkboxes
Turn windows features on or off
  • Open Task Manager & go to Performance Section. Check if virtualization is enabled or not. If not, then enable it from your bios mode.
Turn windows features on or off
  • Open windows powershell as administrator & type the following commands
wsl --update
wsl --list --online
wsl --install -d Ubuntu-22.04
  • Create a new user in ubuntu22 by providing a username & password.
  • Check if the ubuntu is installed or not
lsb_release -a
  • Now you can Open the terminal from your windows 8 select Ubuntu22 to run ubuntu terminal. Also note that, Powershell will be your default terminal application in windows. So to change that, go to settings in Terminal & select default profile as 'Ubuntu22.04'.
Turn windows features on or off
  • Now your Ubuntu 22.04 terminal is ready.
  • Type the following commands to update your ubuntu22 to latest packages
sudo apt update && sudo apt upgrade -y
  • Install a GUI editor for ubuntu22 named gedit
sudo apt install gedit

2. Setting up some utilities for wsl

These utilities are useful to make the wsl work much more like a real Ubuntu distribution.

a. Showing current git branch :

By default the linux terminal doesn't show current git branch in it's prompt. To do this, just add the following line in your .bashrc file

# Show git branch name
force_color_prompt=yes
color_prompt=yes
parse_git_branch() {
 git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
 PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
 PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
fi
unset color_prompt force_color_prompt

The output will be something like this

Showing current git branch

b. Installing Nautilus package :

Nautilus is kind of a gui window that allows you to open any specified path/location in a mini file explorer type window. To install it, run the following command

sudo apt install nautilus

To open a specific location with nautilus use the following syntax nautilus <path-to-folder>.
To open current location with nautilus, use

nautilus .

It will look something like this

Opening current directory with nautilus

c. Installing Gnome-terminal :

By default the wsl terminals doesn't support gnome features.
So in case you use some bash files or python scripts that create multiple gnome tabs, they won't work in default wsl terminals for ubuntu.
In that case, you have to explicitly install gnome-terminal & display it on your screen. To do this, use following commands

sudo apt install gnome-terminal
export DISPLAY=:0
gnome-terminal

It will looke somthing like this (the color will be different, as i have configured it according to my interest)

Opening gnome-terminal

You can just run gnome-terminal command to run the gnome-based terminal.

Note :

The location of C:\Users\username in wsl2 is /mnt/c/Users/username. So if you want to acces this location in wsl2 terminal, you can export this value to an environment variable in your .bashrc file.

export win11='/mnt/c/Users/Mohit'

So you can just do the following command to navigate to your windows's user directory from your wsl2 terminal

cd $win11

3. Removing ubuntu-22.04 & WSL2 completely from windows

  • check what distros you have in wsl2 & unregister them:

Open powersheel & type following commands to unregister your installed linux distros

wsl -l
wsl --unregister Ubuntu-22.04
  • Search for Ubuntu-22.04 in windows search & uninstall it.
  • Type following command in powershell to completely remove WSL2 package update
Get-AppxPackage MicrosoftCorporationII.WindowsSubsystemForLinux | Remove-AppxPackage
  • Uninstall WSL2 by running this command in powershell
wsl --uninstall
  • Search for Turn windows features on or off & uncheck the options you selected in step 1 of Pre-requisites.

About

Setting up WSL2 from scratch to install ubuntu-22 or any other spefic version of ubuntu to run within windows with all it's gui features (most of).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published