This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
A step-by-step guide to the best practices for setting up a WSL development environment. Learn how to run the command to install the default Bash shell that uses Ubuntu or can be set to install other Linux distributions, use basic WSL commands, set up Visual Studio Code or Visual Studio, Git, Windows Credential Manager, databases like MongoDB, Postgres, or MySQL, set up GPU acceleration, run GUI apps, and more.
Windows Subsystem for Linux comes with the Windows operating system, but you must enable it and install a Linux distribution before you can begin using it.
To use the simplified --install command, you must be running a recent build of Windows (Build 20262+). To check your version and build number, selectWindows logo key + R, typewinver, selectOK. You can update using theSettings menu orWindows Update Assistant.
If you prefer to install a Linux distribution other than Ubuntu, or would prefer to complete these steps manually, see theWSL installation page for more details.
Open PowerShell (or Windows Command Prompt) and enter:
wsl --installThe--install command performs the following actions:
You will need to restart your machine during this installation process.

Check thetroubleshooting installation article if you run into any issues.
Once the process of installing your Linux distribution with WSL is complete, open the distribution (Ubuntu by default) using the Start menu. You will be asked to create aUser Name andPassword for your Linux distribution.
ThisUser Name andPassword is specific to each separate Linux distribution that you install and has no bearing on your Windows user name.
Please note that whilst entering thePassword, nothing will appear on screen. This is called blind typing. You won't see what you are typing, this is completely normal.
Once you create aUser Name andPassword, the account will be your default user for the distribution and automatically sign-in on launch.
This account will be considered the Linux administrator, with the ability to runsudo (Super User Do) administrative commands.
Each Linux distribution running on WSL has its own Linux user accounts and passwords. You will have to configure a Linux user account every time you add a distribution, reinstall, or reset.
Note
Linux distributions installed with WSL are a per-user installation and can't be shared with other Windows user accounts. Encountering a username error?StackExchange: What characters should I use or not use in usernames on Linux?

To change or reset your password, open the Linux distribution and enter the command:passwd. You will be asked to enter your current password, then asked to enter your new password, and then to confirm your new password.
If you forgot the password for your Linux distribution:
Open PowerShell and enter the root of your default WSL distribution using the command:wsl -u root
If you need to update the forgotten password on a distribution that is not your default, use the command:
wsl -d <DistroName> -u root, replacing<DistroName>with the name of your targeted distribution.
Once your WSL distribution has been opened at the root level inside PowerShell, you can use this command to update your password:passwd <username> where<username> is the username of the account in the distribution whose password you've forgotten.
You will be prompted to enter a new UNIX password and then confirm that password. Once you're told that the password has updated successfully, close WSL inside of PowerShell using the command:exit.
We recommend that you regularly update and upgrade your packages using the preferred package manager for the distribution. For Ubuntu or Debian, use the command:
sudo apt update && sudo apt upgradeWindows does not automatically update or upgrade your Linux distribution(s). This is a task that most Linux users prefer to control themselves.
To add additional Linux distributions, you can install via theMicrosoft Store, via the--import command, or bysideloading your own custom distribution. You may also want toset up custom WSL images for distribution across your enterprise company.
Windows Terminal can run any application with a command line interface. Its main features include multiple tabs, panes, Unicode and UTF-8 character support, a GPU accelerated text rendering engine, and the ability to create your own themes and customize text, colors, backgrounds, and shortcuts.
Whenever a new WSL Linux distribution is installed, a new instance will be created for it inside the Windows Terminal that can be customized to your preferences.
We recommend using WSL with Windows Terminal, especially if you plan to work with multiple command lines. See the Windows Terminal docs for help with setting it up and customizing your preferences, including:

To open your WSL project in Windows File Explorer, enter:explorer.exe .
Be sure to add the period at the end of the command to open the current directory.
Store your project files on the same operating system as the tools you plan to use.
For the fastest performance speed, store your files in the WSL file system if you are working on them with Linux tools in a Linux command line (Ubuntu, OpenSUSE, etc). If you're working in a Windows command line (PowerShell, Command Prompt) with Windows tools, store your files in the Windows file system. Files can be accessed across the operating systems, but it may significantly slow down performance.
For example, when storing your WSL project files:
\\wsl$\<DistroName>\home\<UserName>\ProjectC:\Users\<UserName>\Project or/mnt/c/Users/<UserName>/Project$
We recommend using Visual Studio Code or Visual Studio, as they directly support remote development and debugging with WSL. Visual Studio Code allows you to use WSL as a full-featured development environment. Visual Studio offers native WSL support for C++ cross-platform development.
Follow this step-by-step guide toGet started using Visual Studio Code with WSL, which includes installing theRemote Development extension pack. This extension enables you to run WSL, SSH, or a development container for editing and debugging with the full set of Visual Studio Code features. Quickly swap between different, separate development environments and make updates without worrying about impacting your local machine.
Once VS Code is installed and set up, you can open your WSL project with a VS Code remote server by entering:code .
Be sure to add the period at the end of the command to open the current directory.

Follow this step-by-step guide toGet started using Visual Studio with WSL for C++ cross-platform development. Visual Studio 2022 enables you to build and debug CMake projects on Windows, WSL distributions, and SSH connections from the same instance of Visual Studio.

Follow this step-by-step guide toGet started using Git on WSL and connect your project to the Git version control system, along with using the credential manager for authentication, using Git Ignore files, understanding Git line endings, and using the Git commands built-in to VS Code.

Follow this step-by-step guide toGet started with Docker remote containers on WSL 2 and connect your project to a remote development container with Docker Desktop for Windows.

Follow this step-by-step guide toGet started with databases on WSL and connect your project to a database in the WSL environment. Get started with MySQL, PostgreSQL, MongoDB, Redis, Microsoft SQL Server, or SQLite.

Follow this step-by-step guide to set upGPU accelerated machine learning training in WSL and leverage your computer's GPU (graphics processing unit) to accelerate performance heavy workloads.

The Linux distributions that you install via WSL are best managed using PowerShell or Windows Command Prompt (CMD). See theWSL command reference guide for a list of basic commands to be familiar with when using WSL.
In addition, many commands are interoperable between Windows and Linux. Here are a couple of examples:
Run Linux tools from a Windows command line: Open PowerShell and display the directory contents ofC:\temp> using the Linuxls -la command by entering:wsl ls -la
Mix Linux and Windows commands: In this example, the Linux commandls -la is used to list files in the directory, then the PowerShell commandfindstr is used to filter the results for words containing "git":wsl ls -la | findstr "git". This could also be done mixing the Windowsdir command with the Linuxgrep command:dir | wsl grep git.
Run a Windows tool directly from the WSL command line:<tool-name>.exeFor example, to open your .bashrc file (the shell script that runs whenever your Linux command line is started), enter:notepad.exe .bashrc
Run the Windows ipconfig.exe tool with the Linux Grep tool: From Bash enter the commandipconfig.exe | grep IPv4 | cut -d: -f2 or from PowerShell enteripconfig.exe | wsl grep IPv4 | wsl cut -d: -f2This example demonstrates the ipconfig tool on the Windows file system being used to display the current TCP/IP network configuration values and then being filtered to only the IPv4 result with grep, a Linux tool.
Follow this step-by-step guide toGet started mounting a Linux disk in WSL 2.

Follow this tutorial to learn how to set up andrun Linux GUI apps on WSL.
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?