This repository demonstrates how to setup wsl2 (Windows Subsystem of Linux 2) for using Ubuntu-22.04 LTS winthin windows.
- Go to search & type 'Turn windows features on or off' & select the following checkboxes
- Open Task Manager & go to Performance Section. Check if virtualization is enabled or not. If not, then enable it from your bios mode.
- 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'.
- 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
- Setup Git with SSH/GPG keys on your local system.
These utilities are useful to make the wsl work much more like a real Ubuntu distribution.
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
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
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)
You can just run gnome-terminal
command to run the gnome-based terminal.
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
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 ofPre-requisites
.