This WSL2 Home windows 10 & 11 tutorial demonstrates set up, handle, and use a full Linux setting in your Home windows 10 or Home windows 11 PC with WSL2. You’ll run a Linux kernel utilizing the Home windows subsystem for Linux and execute native functions whereas seamlessly sharing information and providers with Windows code editors and browsers.
Key Takeaways
- Study Home windows WSL2: Offers an in depth WSL2 tutorial for organising and utilizing Linux on each Home windows 10 and Home windows 11.
- Accessing information: Learn to WSL2 entry information from Home windows and Home windows information from WSL2 to simply work with information throughout each techniques.
- A number of Linux Distros: Perceive handle a number of Linux distributions utilizing Home windows WSL2.
- Working GUI Functions: Learn to run Linux GUI functions instantly in your Home windows desktop with WSL2.
- Integration with Docker: Learn to use Docker Desktop with WSL2 for environment friendly container administration.
Why Use Linux?
Your net host nearly definitely makes use of Linux. It’s quick, open supply, and runs the vast majority of net software program, together with:
- Servers (Apache, NGINX, LiteSpeed, and so on.)
- Language runtimes (PHP, Python, Node.js, Ruby, and so on.)
- Utility libraries (picture manipulation, ZIP creation, emailers, and so on.)
- Databases (MySQL, MongoDB, Redis, and so on.)
- Different dependencies (Elasticsearch, RabbitMQ, proxies, and so on.)
A few of these dependencies could also be out there on Home windows and macOS, however putting in and sustaining an identical variations is tough. They’re typically slower and you could encounter refined variations which is not going to change into obvious till you deploy.
Nevertheless, we are able to’t all the time use Linux as the first OS on our laptops. For instance, if you’re utilizing non-Linux software program akin to Microsoft or Adobe merchandise, you need to use Home windows or macOS. However there are a number of options we are able to use:
- Use two PCs or dual boot on a single gadget. Switching between techniques will be cumbersome.
- Run a Linux digital machine (VM) utilizing Hyper-V, VirtualBox, Parallels, WMware, or Vagrant. This requires appreciable OS assets and cheap IT data. Sharing information between techniques will be awkward.
- Run net functions in Docker containers. It’s one other matter to study and Docker itself runs natively on Linux. Each the Home windows and macOS editions use Linux under the floor and the Home windows version of Docker Desktop requires WSL2.
What’s the Home windows Subsystem for Linux?
The Home windows WSL2 lets builders run a Linux setting instantly on Home windows. It’s a full Linux OS working inside Home windows, so you need to use the identical apps and information seamlessly.
WSL1 was groundbreaking and translated Linux system calls to Home windows equivalents. However it was sluggish, and a few options weren’t out there. WSL2 makes use of Hyper-V digital machine expertise, so Linux compatibility is great, and file entry is as much as 20x quicker than earlier than.
Home windows 10 and Home windows 11 Variations
Microsoft launched WSL 2 in 2020, so it was totally built-in into the Home windows 11 launch in October 2021.
Home windows 10 requires a little bit extra configuration effort. In case you’re contemplating an improve to Home windows 11, do it earlier than putting in WSL 2. Home windows 11 shouldn’t be an enchancment in some respects (I nonetheless miss the taskbar icon ungrouping and dragging information!), however WSL 2 appears extra steady, and I hardly ever encounter points.
PC Necessities
WSL 2 makes use of Hyper-V. This requires {hardware} virtualization help, which you need to allow in your BIOS.
WARNING: Fiddling along with your BIOS settings can trash your PC! Watch out when making modifications. Seek the advice of your motherboard producer’s assist pages or seek for on-line recommendation about your particular make and mannequin.
{Hardware} virtualization is accessible on most trendy gadgets, however you’ll be able to verify by rebooting and opening the BIOS panels — sometimes by hitting the DEL, F2, or F10 key because the system begins. Search for Virtualization Expertise, VTx, Safe Digital Machine (SVM), or comparable choices. Guarantee they’re enabled, and save and reboot the machine.
Lastly, guarantee your C: drive has 1GB of spare disk house — ideally extra. You might be able to release some house in Settings, System, Storage, or utilizing the Disk clean-up instrument in Home windows Administrative Instruments.

WSL 2 will set up your Linux distribution inside a hidden folder in your C: drive by default. It’s doable to move it elsewhere after set up.
Home windows Necessities
WSL2 is accessible with the Dwelling, Professional, or Server editions of Home windows however not Home windows 10/11 S. S mode solely permits apps from the Microsoft Retailer to “enhance” safety. You may swap from S mode to Home windows Dwelling/Professional utilizing the Swap to Home windows Dwelling choice in Settings > Replace & Safety > Activation.
Home windows 10 requires the Might 2020 replace —model 2004 or above. To replace, select Settings from the Begin menu, then choose System, adopted by About. The Home windows specs are proven on the backside of the panel.

If it’s not put in, use the Test for Updates button in Settings, then Replace & Safety. Nevertheless, some older Home windows machines could by no means be suitable, and Microsoft will unlikely provide a patch.
Disable Quick Begin-up (Non-compulsory)
Quick start-up saves the Home windows session and gadget drivers to a file so the subsequent boot is quicker. This could trigger issues for the Linux kernel, which turns into unresponsive on the subsequent boot. In case you encounter issues, disable quick start-up from the traditional Management Panel > Energy Choices > Select what the facility buttons do:

Alternatively, create a wsl.bat file in your Startup folder (C:Customers
wsl --shutdown
It will shut down WSL after Home windows boots however it can restart as quickly as you entry a Linux distro.
Set up Home windows Terminal (Non-compulsory however Really helpful)
Windows Terminal is a good terminal utility out there from the Microsoft Retailer or its repository at github.com/microsoft/terminal/.
Home windows Terminal robotically provides WSL2 Linux distros after they’re put in and presents a configurable vary of choices together with tabs, break up views, themes, transparency, and key bindings.
Configuration is accessible from the Settings menu merchandise (Ctrl + ,), the Command Palette (Ctrl + Shift + P), or the settings.json accessed on the backside of the Settings panel.

Allow WSL2 (Home windows 10)
The steps on this WSL2 tutorial apply to WSL2 Home windows 10. Nevertheless, they need to additionally work advantageous in Home windows 11, though it is best to double-check in case you carried out a Home windows 10 to 11 improve.
The Digital Machine Platform and Home windows Subsystem for Linux options should be enabled in Flip Home windows options on or off choice. The panel is accessed by hitting Begin and typing “options” or from the Packages and Options icon within the traditional Management Panel.

Alternatively, you’ll be able to execute the next instructions in a Home windows Powershell terminal run as an Administrator:
dism.exe /on-line /enable-feature /featurename:Microsoft-Home windows-Subsystem-Linux /all /norestart
dism.exe /on-line /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Reboot Home windows, then begin WSL2 because the default by getting into the next command in a Home windows PowerShell or command immediate:
wsl --set-default-version 2
Obtain Linux
Seek for or find PowerShell within the Begin menu, right-click the icon, and select Run as administrator. Show an inventory of accessible Linux distros by getting into:
wsl --list --online

To put in the default Ubuntu 20.04 distro, enter:
wsl --install
To put in a particular distro by identify, akin to Debian, enter:
wsl --install -d Debian
Alternatively, you’ll be able to set up Linux distros from the Microsoft Retailer, which will be accessed from the Begin menu. Enter “Linux” within the search field (be cautious that software program aside from WSL distros could also be out there).

Ubuntu is an effective alternative until you may have particular Linux necessities. The newest version is put in after you click on the Ubuntu icon and observe the Get button.
The obtain and set up could take a while, relying in your community and PC pace. You could be prompted to reboot once more.
Launch Linux
A brand new Linux (Ubuntu) choice/icon will now be out there in:
- The Begin menu
- Home windows Terminal (if put in)
- Powershell — enter wsl or bash on the immediate
Third-party terminal software program akin to Cmder, ConEmu, or Hyper can be utilized by creating profiles which launch %windirpercentsystem32bash.exe ~.
The set up course of will likely be full the primary time you run the WSL2 Linux OS.
Observe: You could see a message within the terminal a couple of kernel replace. Copy the hyperlink into your browser, then obtain and set up the replace. You’ll must launch the Linux distro once more to proceed the set up.
You’ll be prompted to enter a username and password. These are the credentials for Linux administration: they’re utterly separate out of your Home windows username and password (though selecting the identical ones could also be sensible).
Linux will finally be prepared, and your terminal will present content material just like the next:
Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.10.102.1-microsoft-standard-WSL2 x86_64)
* Documentation: https://assist.ubuntu.com
* Administration: https://panorama.canonical.com
* Help: https://ubuntu.com/benefit
System data as of Tue Aug 16 10:19:36 BST 2022
System load: 0.0 Processes: 8
Utilization of /: 1.6% of 250.98GB Customers logged in: 0
Reminiscence utilization: 1% IPv4 deal with for eth0: 172.21.6.83
Swap utilization: 0%
0 updates will be utilized instantly.
The listing of accessible updates is greater than per week previous.
To verify for brand new updates run: sudo apt replace
Replace Linux
There are more likely to be a number of Linux updates. To replace Ubuntu functions, enter the next instructions within the Linux terminal:
sudo apt replace
sudo apt improve
Different Linux distros could have an identical course of — so verify the documentation for help.
You may as well verify for Linux kernal updates from Powershell utilizing:
wsl --update
Swap Between WSL1 and WSL2
Current WSL1 distros will be transformed to WSL2. For that, enter the next command in a Home windows Powershell terminal to show the put in Linux distros and their WSL model:
PS C:> wsl --list --verbose
NAME STATE VERSION
* Ubuntu Working 1
(The * asterisk highlights the default Linux set up.)
To change Ubuntu to WSL2, enter:
wsl --set-version Ubuntu 2
Equally, to modify again to WSL1, enter:
wsl --set-version Ubuntu 1
Set a Default Linux Distribution
One Linux distribution should be set because the default when you may have a couple of put in. This will likely be used when wsl is entered in a Home windows Powershell terminal.
To set the default distro, listing your Linux installations:
wsl --list
and set a default with:
wsl --setdefault
Ubuntu instance: wsl –setdefault Ubuntu.
Run Linux as a Particular Person
To run your default distribution as a particular consumer, enter the next command in a Home windows Powershell terminal:
wsl --user
A default consumer is outlined during installation however you’ll be able to create others. A root consumer can also be created, however it is best to keep away from utilizing it underneath regular circumstances. It’s too straightforward to enter a harmful command!
Transfer or Clone Your Linux Disk Picture
Linux disk photographs are put in in your C: drive. Optionally, you’ll be able to both:
- Transfer it to a different drive to release house on C:, or
- Use the identical picture to create a number of Linux installations (which will be helpful in case you want totally different functions and setups for various tasks — though Docker may be more practical)
The next directions presume you’re transferring the Ubuntu Linux distro to D:wsl.
In a Home windows Powershell terminal (not the Ubuntu terminal), enter wsl –listing to view your Linux distributions, then export one by identify to a backup .tar file — akin to D:backupubuntu.tar:
mkdir D:backup
wsl --export Ubuntu D:backupubuntu.tar
Unregister that distro to take away it from the C: drive:
wsl --unregister Ubuntu
Enter wsl –listing to confirm the distro has been eliminated.
Import the backup into a brand new WSL2 distro at one other location, akin to D:wsl:
mkdir D:wsl
wsl --import Ubuntu D:wsl D:backupubuntu.tar
You can also make any variety of named clones from the identical back-up. For instance:
wsl --import Clone01 D:wsl D:backupubuntu.tar
wsl --import One other D:wsl D:backupubuntu.tar
Confirm the WSL distro has been efficiently created by getting into wsl –listing and launching Ubuntu from the Begin menu or Home windows Terminal.
At this level, Ubuntu will use root because the default consumer. To revert to your personal account, enter the next command:
ubuntu config --default-user
Right here,
For different distros that aren’t the WSL Home windows default, outline a consumer by logging on to the distro and creating/modifying /and so on/wsl.conf:
contact /and so on/wsl.conf
nano /and so on/wsl.conf
Add the next strains to the file:
[user]
default=
Save (Ctrl + O) and exit (Ctrl + X), then restart the distro in a Powershell terminal with:
wsl --terminate
Presuming all has gone properly, you’ll be able to delete the backup file (D:backupubuntu.tar).
Entry Linux Recordsdata from Home windows
You may entry WSL2 information from Home windows by navigating to wsl$. Enter it within the File Explorer deal with bar or any file open dialog.
Your put in Linux distros are listed, so you’ll be able to entry the Ubuntu root listing at wsl$Ubuntu. Your private Linux information are sometimes be saved at:
wsl$Ubuntuhome
Right here,
It’s finest to set this because the beginning folder for the distro in Home windows Terminal. Open the Settings, click on a profile, then change the Beginning listing choice.
Map a Community Drive
You may mount a community drive to wsl$Ubuntu by opening wsl$ in File Explorer, right-clicking the Ubuntu folder, and selecting Map community drive….

Sadly, it’s not at the moment doable to map deeper subdirectories. You may additionally encounter mapped-drive points with some functions.
Accessing Home windows Recordsdata from Linux
The WSL2 entry Home windows information functionality permits seamless interplay with information saved in your Home windows drives by way of the /mnt/ listing. For instance, your private Customers folder at C:Customers
/mnt/c/Customers/
Right here,
For ease of entry, you’ll be able to create a Linux symbolic hyperlink to any Home windows folder from the terminal. For instance, for C:projectscode:
cd ~
ln -s /mnt/c/tasks/code/
A code folder will seem in your Linux dwelling listing. Navigate to it utilizing cd ~/code and also you’ll really be in /mnt/c/tasks/code/, which maps on to C:projectscode.
Accessing Home windows information from Linux is significantly slower than utilizing the native Linux file system. The place doable, create tasks within the Linux file house, sometimes in your house folder (/dwelling/
Run Linux Instructions from Home windows
Any Linux (bash) shell command will be run from a Home windows Powershell or command-line terminal utilizing wsl:
wsl
For instance, wsl ls -la lists all information in a Home windows folder.
Run Home windows Functions from Linux
Via Home windows WSL2, you’ll be able to launch Home windows functions like Notepad or VS Code instantly out of your Linux setting.
explorer.exe .
Or edit .bashrc in Notepad:
notepad.exe ~/.bashrc
Or open the a particular undertaking listing in VS Code:
code ~/tasks/mywebsite
Set up Functions
At all times keep in mind you’re working two working techniques. They could be tightly built-in, however there are conditions once you need an utility put in in all places.
For instance, Git is helpful in each Home windows and Linux. The Home windows version is put in by downloading an executable. It’s finest to make sure it doesn’t convert line endings:
git config --global core.autocrlf enter
Git on Ubuntu is put in utilizing:
sudo apt replace
sudo apt set up git-all
Equally, you could wish to check Node.js functions on each Home windows and Linux. Once more, Windows has a runtime installer whereas Node.js runtime is installed on Ubuntu utilizing instructions akin to:
sudo apt-get set up build-essential
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get set up -y nodejs
git, node and npm commands will now work in both OS. Be cautious that they might be totally different variations.
Putting in Graphical Linux Functions
WSL Home windows lets you run graphical X11 and Wayland Linux functions instantly on Home windows. You may launch Linux apps from the Begin menu, pin them to the duty bar, and use options akin to minimize and paste throughout functions. There are some downsides:
- Not all graphical apps will work as anticipated.
- Some provide Linux options — akin to file dialogs — that would confuse Home windows customers.
- There’s little profit in putting in functions with native Home windows editions akin to Firefox, VLC, or GIMP.
To proceed, set up the right GPU driver to your Home windows machine:
Then, set up any graphical utility from the Linux terminal. For instance, the GNOME Gedit text editor:
sudo apt set up gedit
Launch it with:
gedit
Pin the app to your Begin menu or process bar like some other Home windows program.
Gedit is a small utility with a obtain dimension of lower than 2MB. Nevertheless, it requires GNOME and different Linux libraries, which incur a number of hundred megabytes of further code on prime of the chunky GPU drivers (1.1GB for Intel). Utilizing graphical Linux apps in WSL2 solely is sensible if it’s essential to set up a number of functions or there’s no native Home windows different.
Putting in Docker
One exception to the “set up on each OSes” rule is Docker!
Docker runs functions in remoted Linux containers which might be conceptually just like light-weight digital machines with an OS, single utility, and its dependencies. Utilizing Docker for net growth offers a constant setting that’s straightforward to put in and works on any gadget.
Docker Desktop for Windows is totally WSL2-enabled:
- there’s no want to make use of Hyper-V, so Docker will be put in on Home windows Dwelling
- Docker begins and runs significantly quicker when configured to make use of WSL2
- putting in Docker Desktop on Home windows permits docker and docker-compose in each Home windows and Linux
Docker Desktop suggests you utilize WSL2 when it’s first launched. Alternatively, you’ll be able to choose Settings from the Docker system tray icon menu, then select the Common tab, verify Use the WSL 2 primarily based engine, and hit Apply & Restart.

Docker makes use of the default Linux distro, however you may also allow it in different put in distros from the WSL Integration panel in Settings, then Assets.
Launching Apache and PHP Functions Utilizing Docker
Putting in net dependencies akin to Apache and PHP instantly in your WSL2 Linux setting is feasible. Nevertheless, Docker is safer, faster, and extra configurable: it lets you run totally different variations of PHP on the identical gadget concurrently.
On this instance, you’ll create a small PHP file and run it utilizing the most recent launch of PHP 7.4 in a Docker container. Make sure you’ve put in Docker Desktop for Windows and enabled WSL2 mode, then create a folder in your Linux setting with an index.php file. For instance:
mkdir ~/php
cd ~/php
contact index.php
Edit index.php, maybe using Notepad or VS Code as shown above. Add the next content material, which outputs PHP standing data:
Run the next docker command to start out a PHP 8.1-enabled Apache net server in a container which mounts information within the present host listing to /var/www/html within the container:
docker run
-it --rm -p 8080:80 --name php
-v "$PWD":/var/www/html
php:8.1-apache
Observe: this command additionally works in Home windows, however the reference to $PWD should be changed by the complete file path in Linux notation — akin to /c/php/.
Open https://localhost:8080/ in any Home windows net browser to view the output of the phpinfo() command.
To complete, press Ctrl + C in your Docker terminal to cease and delete the container.
WSL2 and localhost
Home windows, WSL2 Linux, and Docker container functions are all the time accessed from localhost or 127.0.0.1.
The PHP example above uncovered port 8080, which was mapped to port 80 within the container. Equally, if in case you have Node.js put in in Linux, you’ll be able to cd to any listing and begin a static file server:
npx small-static-server
Open http://localhost:8888/ in a browser to view information in that listing (index.html is returned by default).
Remember that ports out there in a single OS could also be unavailable within the different. Port numbers lower than 1,000 are solely out there to Linux tremendous customers. The Home windows Retailer Skype App typically reserves port 80 and might’t be modified (though the traditional Desktop edition permits it).
SSL certificates which might be both self-signed or regionally trusted utilizing instruments akin to mkcert can be utilized interchangeably in each Home windows and Linux environments.
VS Code WSL2 Integration
In VS Code, you can begin WSL2 periods instantly from the built-in terminal. Open the terminal with View > Terminal or Ctrl + ‘ then hit the down arrow subsequent to the + icon to launch a particular sort. The identical menu has a Choose Default Profile choice the place you’ll be able to choose the terminal to make use of by default.

With VS Code, you’ll be able to instantly entry WSL2 information from Home windows at wsl$ and debuggers working on localhost. There’s no want for additional extensions, however the next choices allow simpler Linux and Docker file administration:
After putting in Distant – WSL, you’ll be able to navigate to any Linux listing and launch a WSL-connected occasion of VS Code:
cd ~/myproject
code .
Alternatively, click on the distant window icon within the backside left of the applying, then select a connection choice.

Or, you need to use the brand new Distant Explorer icon within the Exercise Bar. This allows you to select a goal sort from the drop-down menu and join accordingly.

The distant occasion of VS Code has separate extensions and settings for Linux use, however some will be globally enabled. The Extensions panel lets you allow and configure extensions within the distant occasion.

Settings are saved in your Linux ~/.vscode-server listing.
Abstract
This WSL2 tutorial has proven make the most of WSL2 Home windows 11 for working Linux functions in your Home windows machine. Working Linux functions on Home windows used to require digital machines, complicated Samba folder shares, and plenty of persistence. WSL2 has revolutionized net growth. It makes it straightforward to write code utilizing Home windows instruments after which run it in a production-like Linux setting. The tight integration presents the advantages of each OSes.
Additional WSL2 assets:
In case you loved this text, you may additionally discover these assets helpful too:
FAQs About Home windows Subsystem for Linux 2
What Is the Distinction Between WSL1 and WSL2?
WSL1 and WSL2 are each Microsoft’s Home windows Subsystem for Linux, however they function in a different way. WSL1 interprets Linux system calls into Home windows system calls, which may result in compatibility points with sure Linux functions. However, WSL2 makes use of a light-weight digital machine to run a full Linux kernel, offering higher compatibility and efficiency, particularly for file system heavy operations. Nevertheless, WSL2 could devour extra system assets than WSL1.
How Can I Improve from WSL1 to WSL2?
Upgrading from WSL1 to WSL2 is a simple course of. First, it’s essential to be sure that your Home windows 10 model helps WSL2. Then, open PowerShell as an administrator and run the command wsl –set-version
Can I Use GUI Functions with WSL2?
Sure, you need to use GUI functions with WSL2. Microsoft has launched help for GUI functions in WSL2 with the Home windows 10 Might 2021 replace. This implies you’ll be able to run Linux GUI functions instantly in your Home windows desktop without having a separate X server.
How Can I Set up a New Linux Distribution with WSL2?
You may set up new Linux distributions with WSL2 Home windows 11 from the Microsoft Retailer. Open the Microsoft Retailer, seek for the Linux distribution you wish to set up, and click on the “Get” button. As soon as the set up is full, begin WSL2 by launching the distribution from the Begin menu.
How Can I Entry My Home windows Recordsdata from WSL2?
You may entry your Home windows information from WSL2 by way of the /mnt/ listing. For instance, your C: drive is accessible at /mnt/c/. You may navigate to this listing utilizing the cd command.
Is It Attainable to Run Docker with WSL2?
Sure, it’s doable to run Docker with WSL2. Docker has launched help for WSL2 with the Docker Desktop for Home windows. This lets you run Docker containers instantly out of your WSL2 Linux distribution.
How Can I Replace My WSL2 Linux Kernel?
You may replace your WSL2 Linux kernel by downloading and putting in the most recent WSL2 Linux kernel replace bundle from the Microsoft web site. After the set up is full, it’s essential to restart your laptop for the modifications to take impact.
Can I Use A number of Linux Distributions with WSL2?
Sure, you’ll be able to handle a number of Linux distributions with Home windows WSL2. Every linux distribution runs in its personal setting, and you’ll swap between them as wanted. You may set up further linux distributions from the Microsoft Retailer.
How Can I Uninstall a Linux Distribution from WSL2?
You may uninstall a Linux distribution from WSL2 by right-clicking on the distribution within the Begin menu and deciding on “Uninstall”. Alternatively, you need to use the wsl –unregister
Can I Use WSL2 with Home windows 11?
Sure, you need to use WSL2 with Home windows 11. Actually, Home windows 11 has launched a number of enhancements to WSL2, together with quicker startup occasions and higher system efficiency.
How Can I Swap Between Linux Distros in WSL2?
By default, the wsl command will open the default linux distro, however you’ll be able to specify a unique one through the use of the “-d” flag adopted by the distro’s identify. For instance, to modify to a distro named “Debian,” you’ll use the command wsl -d Debian.
How Do I Replace a Linux Distro in WSL2?
Open the terminal for the particular Linux distro and use the bundle supervisor to replace it. For instance, on an Ubuntu-based distro, you’ll be able to run “sudo apt replace && sudo apt improve”.