This WSL2 Home windows 10 & 11 tutorial demonstrates tips on how to set up, handle, and use a full Linux atmosphere 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 recordsdata and companies with Home windows code editors and browsers.
Key Takeaways
- WSL2 permits seamless integration of a Linux atmosphere on Home windows 10 and 11, enabling using Linux functions and recordsdata alongside Home windows assets.
- Set up and setup of WSL2 are extra streamlined on Home windows 11 in comparison with Home windows 10, which requires enabling digital machine options manually.
- Linux GUI functions will be run immediately in Home windows with WSL2, enhancing usability with out the necessity for extra X server software program.
- Docker will be effectively utilized inside WSL2, benefiting from sooner startup instances and higher efficiency without having devoted Hyper-V.
- Entry to Home windows recordsdata from Linux and vice versa is facilitated via mounting and symbolic hyperlinks, permitting straightforward file sharing and administration throughout methods.
- VS Code integration with WSL2 gives a sturdy improvement atmosphere, enabling direct entry to Linux recordsdata and terminals from throughout the editor.
Why Use Linux?
Your net host nearly actually makes use of Linux. It’s quick, open supply, and runs nearly all of net software program, together with:
- Servers (Apache, NGINX, LiteSpeed, and many others.)
- Language runtimes (PHP, Python, Node.js, Ruby, and many others.)
- Utility libraries (picture manipulation, ZIP creation, emailers, and many others.)
- Databases (MySQL, MongoDB, Redis, and many others.)
- Different dependencies (Elasticsearch, RabbitMQ, proxies, and many others.)
A few of these dependencies could also be obtainable on Home windows and macOS, however putting in and sustaining similar variations is tough. They’re usually slower and it’s possible you’ll encounter delicate variations which won’t turn 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 equivalent to Microsoft or Adobe merchandise, you have to use Home windows or macOS. However there are a couple of options we are able to use:
- Use two PCs or twin boot on a single gadget. Switching between methods 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 recordsdata between methods 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 atmosphere immediately on Home windows. It’s a full Linux OS operating inside Home windows, so you should use the identical apps and recordsdata seamlessly.
WSL1 was groundbreaking and translated Linux system calls to Home windows equivalents. But it surely was sluggish, and a few options weren’t obtainable. WSL2 makes use of Hyper-V digital machine know-how, so Linux compatibility is great, and file entry is as much as 20x sooner 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 just a little extra configuration effort. Should you’re contemplating an improve to Home windows 11, do it earlier than putting in WSL 2. Home windows 11 just isn’t an enchancment in some respects (I nonetheless miss the taskbar icon ungrouping and dragging recordsdata!), however WSL 2 appears extra secure, and I not often encounter points.
PC Necessities
WSL 2 makes use of Hyper-V. This requires {hardware} virtualization assist, which you have to allow in your BIOS.
WARNING: Fiddling along with your BIOS settings can trash your PC! Watch out when making adjustments. 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 fashionable units, however you’ll be able to examine 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 related 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 device 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 potential to transfer it elsewhere after set up.
Home windows Necessities
WSL2 is accessible with the Residence, 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 Residence/Professional utilizing the Swap to Home windows Residence possibility 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 Examine for Updates button in Settings, then Replace & Safety. Nevertheless, some older Home windows machines could by no means be appropriate, and Microsoft will unlikely supply a patch.
Disable Quick Begin-up (Elective)
Quick start-up saves the Home windows session and gadget drivers to a file so the subsequent boot is quicker. This may trigger issues for the Linux kernel, which turns into unresponsive on the subsequent boot. Should you encounter issues, disable quick start-up from the basic 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 would restart as quickly as you entry a Linux distro.
Set up Home windows Terminal (Elective however Advisable)
Home windows Terminal is a good terminal software obtainable from the Microsoft Retailer or its repository at github.com/microsoft/terminal/.
Home windows Terminal robotically provides WSL2 Linux distros once they’re put in and provides 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 high quality in Home windows 11, though you need to double-check in the event 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 possibility. The panel is accessed by hitting Begin and typing “options” or from the Applications and Options icon within the basic 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 a listing of obtainable 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, equivalent 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 obtainable).

Ubuntu is an effective alternative except you’ve 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. Chances are you’ll be prompted to reboot once more.
Launch Linux
A brand new Linux (Ubuntu) possibility/icon will now be obtainable in:
- The Begin menu
- Home windows Terminal (if put in)
- Powershell — enter wsl or bash on the immediate
Third-party terminal software program equivalent to Cmder, ConEmu, or Hyper can be utilized by creating profiles which launch %windirpercentsystem32bash.exe ~.
The set up course of shall be full the primary time you run the WSL2 Linux OS.
Be aware: 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 have to 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 much 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 info 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 tackle for eth0: 172.21.6.83
Swap utilization: 0%
0 updates will be utilized instantly.
The checklist of obtainable updates is greater than per week previous.
To examine for brand spanking 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 examine the documentation for help.
You too can examine for Linux kernal updates from Powershell utilizing:
wsl --update
Swap Between WSL1 and WSL2
Present 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 Operating 1
(The * asterisk highlights the default Linux set up.)
To modify Ubuntu to WSL2, enter:
wsl --set-version Ubuntu 2
Equally, to change 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’ve multiple put in. This shall be used when wsl is entered in a Home windows Powershell terminal.
To set the default distro, checklist your Linux installations:
wsl --list
and set a default with:
wsl --setdefault
Ubuntu instance: wsl –setdefault Ubuntu.
Run Linux as a Particular Consumer
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 throughout set up however you’ll be able to create others. A root consumer can be created, however you need 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 the event you want completely different functions and setups for various initiatives — though Docker could also be extra sensible)
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 –checklist to view your Linux distributions, then export one by identify to a backup .tar file — equivalent 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 –checklist to confirm the distro has been eliminated.
Import the backup into a brand new WSL2 distro at one other location, equivalent to D:wsl:
mkdir D:wsl
wsl --import Ubuntu D:wsl D:backupubuntu.tar
You may 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 –checklist 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 individual 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 many others/wsl.conf:
contact /and many others/wsl.conf
nano /and many others/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 effectively, you’ll be able to delete the backup file (D:backupubuntu.tar).
Entry Linux Recordsdata from Home windows
You may entry WSL2 recordsdata from Home windows by navigating to wsl$. Enter it within the File Explorer tackle 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 recordsdata are sometimes be saved at:
wsl$Ubuntuhome
Right here,
It’s greatest 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 possibility.
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 present potential 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 recordsdata functionality permits seamless interplay with recordsdata saved in your Home windows drives via 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/initiatives/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/initiatives/code/, which maps on to C:projectscode.
Accessing Home windows recordsdata from Linux is significantly slower than utilizing the native Linux file system. The place potential, create initiatives 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 recordsdata in a Home windows folder.
Run Home windows Purposes from Linux
Via Home windows WSL2, you’ll be able to launch Home windows functions like Notepad or VS Code immediately out of your Linux atmosphere.
explorer.exe .
Or edit .bashrc in Notepad:
notepad.exe ~/.bashrc
Or open the a particular challenge listing in VS Code:
code ~/initiatives/mywebsite
Set up Purposes
All the time bear in mind you’re operating two working methods. They might be tightly built-in, however there are conditions while you need an software put in in every single place.
For instance, Git is beneficial in each Home windows and Linux. The Home windows version is put in by downloading an executable. It’s greatest 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, it’s possible you’ll need to take a look at Node.js functions on each Home windows and Linux. Once more, Home windows has a runtime installer whereas Node.js runtime is put in on Ubuntu utilizing instructions equivalent 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 instructions will now work in both OS. Be cautious that they could be completely different variations.
Putting in Graphical Linux Purposes
WSL Home windows permits you to run graphical X11 and Wayland Linux functions immediately on Home windows. You may launch Linux apps from the Begin menu, pin them to the duty bar, and use options equivalent to reduce and paste throughout functions. There are some downsides:
- Not all graphical apps will work as anticipated.
- Some supply Linux options — equivalent to file dialogs — that might confuse Home windows customers.
- There’s little profit in putting in functions with native Home windows editions equivalent to Firefox, VLC, or GIMP.
To proceed, set up the proper GPU driver on your Home windows machine:
Then, set up any graphical software from the Linux terminal. For instance, the GNOME Gedit textual content editor:
sudo apt set up gedit
Launch it with:
gedit
Pin the app to your Begin menu or activity bar like every other Home windows program.
Gedit is a small software with a obtain dimension of lower than 2MB. Nevertheless, it requires GNOME and different Linux libraries, which incur a number of hundred megabytes of extra code on high of the chunky GPU drivers (1.1GB for Intel). Utilizing graphical Linux apps in WSL2 solely is sensible if it is advisable 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 much like light-weight digital machines with an OS, single software, and its dependencies. Utilizing Docker for net improvement gives a constant atmosphere that’s straightforward to put in and works on any gadget.
Docker Desktop for Home windows is totally WSL2-enabled:
- there’s no want to make use of Hyper-V, so Docker will be put in on Home windows Residence
- Docker begins and runs significantly sooner when configured to make use of WSL2
- putting in Docker Desktop on Home windows allows docker and docker-compose in each Home windows and Linux
Docker Desktop suggests you employ 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, examine Use the WSL 2 based mostly engine, and hit Apply & Restart.

Docker makes use of the default Linux distro, however you may as well allow it in different put in distros from the WSL Integration panel in Settings, then Assets.
Launching Apache and PHP Purposes Utilizing Docker
Putting in net dependencies equivalent to Apache and PHP immediately in your WSL2 Linux atmosphere is feasible. Nevertheless, Docker is safer, faster, and extra configurable: it permits you to run completely 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 Home windows and enabled WSL2 mode, then create a folder in your Linux atmosphere with an index.php file. For instance:
mkdir ~/php
cd ~/php
contact index.php
Edit index.php, maybe utilizing Notepad or VS Code as proven above. Add the next content material, which outputs PHP standing info:
phpinfo();
Run the next docker command to start out a PHP 8.1-enabled Apache net server in a container which mounts recordsdata 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
Be aware: this command additionally works in Home windows, however the reference to $PWD should be changed by the complete file path in Linux notation — equivalent 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 instance above uncovered port 8080, which was mapped to port 80 within the container. Equally, when 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 recordsdata in that listing (index.html is returned by default).
Bear in mind that ports obtainable in a single OS could also be unavailable within the different. Port numbers lower than 1,000 are solely obtainable to Linux tremendous customers. The Home windows Retailer Skype App usually reserves port 80 and might’t be modified (though the basic Desktop version permits it).
SSL certificates which might be both self-signed or regionally trusted utilizing instruments equivalent 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 immediately 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 possibility the place you’ll be able to choose the terminal to make use of by default.

With VS Code, you’ll be able to immediately entry WSL2 recordsdata from Home windows at wsl$ and debuggers operating 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 appliance, then select a connection possibility.

Or, you should 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 permits you to allow and configure extensions within the distant occasion.

Settings are saved in your Linux ~/.vscode-server listing.
Abstract
This WSL2 tutorial has proven tips on how to make the most of WSL2 Home windows 11 for operating Linux functions in your Home windows machine. Operating Linux functions on Home windows used to require digital machines, advanced Samba folder shares, and many persistence. WSL2 has revolutionized net improvement. It makes it straightforward to write code utilizing Home windows instruments after which run it in a production-like Linux atmosphere. The tight integration provides the advantages of each OSes.
Additional WSL2 assets:
Should 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 otherwise. WSL1 interprets Linux system calls into Home windows system calls, which may result in compatibility points with sure Linux functions. Then again, 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 an easy course of. First, it is advisable 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 Purposes with WSL2?
Sure, you should use GUI functions with WSL2. Microsoft has launched assist for GUI functions in WSL2 with the Home windows 10 Might 2021 replace. This implies you’ll be able to run Linux GUI functions immediately 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 need 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 recordsdata from WSL2 via 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 potential to run Docker with WSL2. Docker has launched assist for WSL2 with the Docker Desktop for Home windows. This lets you run Docker containers immediately 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 is advisable restart your laptop for the adjustments 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 atmosphere, and you may swap between them as wanted. You may set up extra 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 choosing “Uninstall”. Alternatively, you should use the wsl –unregister
Can I Use WSL2 with Home windows 11?
Sure, you should use WSL2 with Home windows 11. Actually, Home windows 11 has launched a number of enhancements to WSL2, together with sooner startup instances 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 distinct one through the use of the “-d” flag adopted by the distro’s identify. For instance, to change 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 precise 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”.