Harness the Combinatoric Power of Command-Line Tools and Utilities

../Tutorials

Install and Configure WSL on Windows

Bash Windows WSL

Published April 28, 2024

Warning

❗ This article is more than six months old. Some things may not work as written.

The Windows Subsystem for Linux (WSL) provides a powerful development environment for developers who need a Linux-based toolset on a Windows machine. WSL allows you to run a Linux distribution alongside your existing Windows applications, enabling you to use Unix tools, run servers, and execute scripts in a Linux environment without leaving Windows. This tutorial will guide you through the installation of WSL using the wsl --install command, which simplifies setting up WSL on Windows 10 or 11.

What You Need

You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11 to follow this tutorial.

Install WSL on Windows

To install WSL on your Windows system, open PowerShell as an Administrator.

  • Right-click on the Start button.
  • Select “Windows PowerShell (Admin)”.

In the PowerShell window, enter the following command:

wsl --install

This command enables the required optional features, downloads the latest Linux kernel, and installs the Ubuntu Linux distribution.

Enabling feature(s)...
Downloading from the Microsoft Store...
Installing Ubuntu...
This will take a few minutes to complete.
Restart your computer to finish the installation.

Wait for the installation to complete and reboot your computer when prompted.

After rebooting, open the newly installed Linux distribution from the Start menu.

You’ll be prompted to create a new user account and password:

Installing, this may take a few minutes...
Please create a new default UNIX user account. The username does not need to match your Windows username.
Enter new UNIX username: your_username
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Installation successful!

Once your account is created, you can use this enviornment to develop software using various Linux tools.

Access Files Between Windows and WSL

Once WSL is installed, you can access your Windows files from within the Linux environment. Here’s how to navigate between the two systems:

Access Windows files from Linux

Your Windows drives are mounted under the /mnt/ directory in WSL. For example, your C drive is available at /mnt/c/.

You can navigate to your Windows files in your Home directory with the following command:

cd /mnt/c/Users/your_windows_username/Documents/

Access Linux files from Windows

You may want to access files from Linux within Windows. The method for this depends on which version of Windows you’re running.

  • In Windows 10, open File Explorer and type \\wsl$ in the address bar to access the Linux file system.
  • In Windows 11, you can also access your Linux files by navigating to the Linux icon in the navigation pane of File Explorer.

Conclusion

With WSL installed, you can enjoy the flexibility of Linux tools while retaining the convenience of Windows applications. This setup is ideal for developers who need to run Linux-specific software or scripts in a native environment. Accessing files between Windows and WSL seamlessly integrates your workflows, making it easier to manage projects across both environments.