Using WSL with Windows Terminal

Windows Subsystem for Linux (WSL) empowers developers to run Linux environments directly on Windows, seamlessly integrating Linux command-line tools, utilities, and applications with your Windows workflow. Windows Terminal, a modern, multi-tabbed terminal application, offers a superb experience for interacting with WSL distributions.

Why Use WSL with Windows Terminal?

Combining WSL and Windows Terminal provides a powerful and flexible development environment. You get the best of both worlds: the rich ecosystem of Linux tools and the familiar, user-friendly interface of Windows.

Getting Started

1. Install WSL

The easiest way to install WSL is by opening PowerShell or Command Prompt as an administrator and running:

PowerShell
wsl --install

This command will enable the necessary features, download the latest Linux kernel, and install a default Linux distribution (usually Ubuntu). You may need to restart your computer. Follow the on-screen instructions to set up a username and password for your Linux distribution.

For more detailed installation steps and to choose specific distributions, refer to the official Microsoft WSL installation guide.

2. Install Windows Terminal

Windows Terminal is available from the Microsoft Store. Search for "Windows Terminal" and install it.

Alternatively, you can install it using PowerShell:

PowerShell
winget install Microsoft.WindowsTerminal

Configuring Windows Terminal for WSL

Once both WSL and Windows Terminal are installed, Windows Terminal will automatically detect your WSL distributions and add them as profiles. You can launch your WSL distribution by clicking the dropdown arrow in the terminal and selecting your distribution's name.

Customizing Your WSL Experience

Windows Terminal is highly customizable. You can access its settings by clicking the dropdown arrow and selecting "Settings".

Appearance Settings

Within the settings, you can:

Key Bindings

Customize keyboard shortcuts for common actions like opening new tabs, splitting panes, copying, and pasting.

WSL Profile Specifics

Each WSL distribution appears as a profile. You can edit these profiles individually. For instance, you might want to start your Ubuntu profile directly in a specific directory:

Tip: To start a WSL profile in a specific directory, edit the profile's "Starting directory" setting in Windows Terminal's JSON settings. You can use paths like \\wsl$\Ubuntu\home\youruser\projects.

You can modify the settings.json file directly for advanced configurations. Access it via the Settings UI ("Open JSON file").

Advanced Usage

Running Linux GUI Apps

With WSLg (WSL Graphical Architecture), you can run Linux GUI applications directly from your WSL distribution within Windows Terminal.

To run a GUI app, simply type its command in your WSL terminal. For example:

WSL Terminal
gedit

This will launch the Gedit text editor within a Windows window.

Interacting with Windows Files

Your Windows drives are mounted under /mnt/ in your WSL distribution. For example, your C: drive is accessible at /mnt/c/.

cd /mnt/c/Users/YourUsername/Documents

Using Git and Other Development Tools

Install your favorite development tools within your WSL distribution. Windows Terminal provides a seamless interface for using them.

WSL Terminal
sudo apt update && sudo apt install git nodejs npm -y

Troubleshooting

If you encounter issues:

By mastering the synergy between WSL and Windows Terminal, you can significantly enhance your development productivity and enjoy a robust, flexible computing environment.