Using Bash on Windows with WSL
Windows does not include Bash by default, because its own shells, Command Prompt and PowerShell, use different languages. The Windows Subsystem for Linux (WSL) closes that gap. It lets you run a real Linux distribution, with a real Bash, directly on Windows without a separate virtual machine window or a dual-boot setup. This lesson explains what WSL is, how to install it, how to start Bash, how Windows and Linux files interact, and what to watch for when scripts cross between the two worlds.
Understanding the Concept
WSL is a Windows feature that runs Linux programs. Current installations use WSL 2, which runs a real Linux kernel inside a lightweight virtual machine that Windows manages for you. From your point of view it behaves like an installed program:
- You open a terminal and get a Linux shell.
- The Linux environment has its own file system, package manager, and users.
- Windows and Linux can reach each other's files and can run each other's programs.
Because it is a real Linux distribution, such as Ubuntu or Debian, the Bash you get is the same Bash described in the Linux lessons, and the commands from the earlier lessons work unchanged.
Requirements
WSL needs a supported version of Windows 10 or Windows 11 with virtualization enabled in the computer's firmware settings. Installation requires administrator rights. The steps below are the standard ones from Microsoft's documentation, so check the official WSL page if your Windows version is older than the current releases.
Installing WSL
Open PowerShell or Windows Terminal as an administrator and run:
wsl --install
This single command enables the required Windows features and installs a default Linux distribution, which is Ubuntu in current releases. Restart the computer when it asks you to. After the restart, the distribution finishes setting itself up and asks you to choose a Linux user name and password. These belong to the Linux environment only and are separate from your Windows account.
To see which distributions are available for installation:
wsl --list --online
To install a specific one, pass its name:
wsl --install -d Debian
The -d option selects the distribution by name, using a name from the online list.
Starting Bash in WSL
After installation, the distribution appears in the Start menu under its own name, such as Ubuntu. Opening it starts a terminal running Bash. You can also start it from PowerShell or Windows Terminal:
wsl
This opens your default distribution and starts its default shell. Because Ubuntu and Debian use Bash as the default shell, you land at a Bash prompt. Confirm it with commands you already know:
echo "$BASH_VERSION"
cat /etc/os-release | head -2
Sample output:
5.2.21(1)-release
PRETTY_NAME="Ubuntu 24.04.1 LTS"
The exact numbers depend on the distribution release you installed. Type exit to leave the Linux shell and return to PowerShell.
You can also run a single Bash command from Windows without opening an interactive session:
wsl ls -l /etc
wsl bash -c "echo hello from Bash"
Everything after wsl is passed to the Linux environment. The second form runs bash -c so that Bash itself interprets the quoted string.
Managing Distributions
Several commands control installed distributions from the Windows side:
| Command | Purpose |
|---|---|
wsl --list --verbose | Show installed distributions, their state, and WSL version |
wsl --set-default <name> | Choose which distribution wsl opens by default |
wsl --update | Update the WSL components |
wsl --shutdown | Stop all running distributions and the WSL virtual machine |
wsl --terminate <name> | Stop one distribution |
For example, wsl --list --verbose prints a table with the name, whether it is running or stopped, and the version number, where 2 means WSL 2.
Files in WSL
The Linux File System
Your Linux home directory lives inside the distribution's own file system. Inside Bash, it is /home/<your-user>, and ~ is shorthand for it. Work you do with Linux tools should normally stay here, because file access inside the Linux file system is fastest and keeps Linux permissions intact.
Reaching Windows Drives
WSL mounts your Windows drives under /mnt. The C: drive appears as /mnt/c:
ls /mnt/c/Users
The command lists the user folders on the Windows C: drive. You can read and change Windows files from Bash this way. Access across this boundary is slower than inside the Linux file system, so avoid keeping large projects with thousands of small files, such as dependency folders, under /mnt/c when you can keep them in your Linux home directory instead.
Reaching Linux Files from Windows
Windows can open Linux files through a network-style path that starts with