To install Ubuntu on Windows Subsystem for Linux (WSL) 2 using the command-line tool, you can follow these step-by-step instructions:
Enable WSL 2:
Before you can install Ubuntu on WSL 2, you need to ensure that WSL 2 is enabled on your Windows system. Open PowerShell as an administrator and run the following commands:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
This enables both WSL and the required virtual machine platform feature.
Download Ubuntu Image
You’ll need to download the Ubuntu image for WSL 2. You can use the following curl
command to download it:
curl -O https://aka.ms/wsl-ubuntu-2004
Install Ubuntu
Use the wsl
command-line tool to install Ubuntu. You can specify the distribution name and set it to use WSL 2. Replace <YourUsername>
with your Windows username:
wsl --import Ubuntu-20.04 C:\WSL\Ubuntu-20.04 .\wsl-ubuntu-2004 --version 2 --user <YourUsername>
Ubuntu-20.04
: This is the name you can choose for your Ubuntu distribution. You can change it if you prefer a different name.C:\WSL\Ubuntu-20.04
: This is the directory where your Ubuntu files will be stored. You can specify a different directory if needed..\wsl-ubuntu-2004
: This should match the name of the downloaded Ubuntu image.--version 2
: This specifies that you want to use WSL 2.--user <YourUsername>
: Replace<YourUsername>
with your Windows username.
Initialize Ubuntu
Start your newly installed Ubuntu distribution and follow the initialization prompts. The first time you launch it, you’ll be asked to create a user and set a password.
wsl -d Ubuntu-20.04
Update Ubuntu
After you’ve created your user and signed in, it’s a good practice to update the package list and upgrade the installed packages:
sudo apt update
sudo apt upgrade
That’s it! You’ve successfully installed Ubuntu on WSL 2 using the command-line tool. You can now use Ubuntu alongside your Windows environment for running Linux commands and applications.
Alternative way
you can download the Ubuntu image for Windows Subsystem for Linux (WSL) 2 directly from the Microsoft Store. Here’s how you can do it:
- Open Microsoft Store:Open the Microsoft Store on your Windows system. You can search for “Microsoft Store” in the Start menu or search bar and open it from there.
- Search for Ubuntu:In the Microsoft Store, use the search bar in the upper-right corner and type “Ubuntu.” Press Enter or click on the search icon.
- Select Ubuntu:From the search results, you should see “Ubuntu” or “Ubuntu 20.04 LTS” (or another version, depending on what’s available at the time). Click on it to open the Ubuntu listing.
- Install Ubuntu:On the Ubuntu listing page, click the “Install” button to initiate the installation. The Microsoft Store will download and install the Ubuntu distribution for WSL 2.
- Launch Ubuntu:After the installation is complete, you can launch Ubuntu from the Start menu or by typing “Ubuntu” in the Windows search bar. This will start the initialization process for Ubuntu, where you’ll set up your user account and password.
Using the Microsoft Store to download and install Ubuntu is a convenient way to ensure that you have the official and up-to-date image for WSL 2. It simplifies the installation process and ensures compatibility with the WSL 2 environment.
Check Available Distributions:
Run the following command to check the available WSL distributions you can install: