How to Install Ubuntu 20.04 in WSL2 on a Windows 10

February 13, 2023 | By Gerald | Filed in: DevOps, Linux, Windows Subsystem.
Install Ubuntu 20.04 in WSL2 on a Windows 10

Installing Ubuntu 20.04 in the Windows Subsystem for Linux 2 (WSL2) is an excellent way to use a Linux environment on your Windows 10 machine without the need for a virtual machine. This can enhance your productivity by allowing you to run Linux distributions directly on Windows.

What is WSL2?

WSL2 (Windows Subsystem for Linux 2) is a feature in Windows 10 that allows you to run Linux applications directly on Windows without the need for a virtual machine. It provides a full Linux environment with complete system call compatibility, allowing you to run Linux applications as if they were native Windows applications.

WSL2 was introduced in Windows 10 version 2004 and is a significant improvement over the original WSL (WSL1) as it uses a lightweight virtual machine to provide better system call compatibility, improved file system performance, and support for Docker containers.

In this guide, we’ll show you the steps to install Ubuntu 20.04 in WSL2 on a Windows 10 machine.

Before you start, make sure you have the following:

  • A Windows 10 machine with version 2004 or later.
  • A Microsoft account with admin privileges.
  • Windows Subsystem for Linux (WSL) feature enabled on your Windows 10 machine.

What to do:

  1. Check your version and build number on Windows
  2. Check if your user has administrator privileges on a Windows
  3. Enable the Windows Machine Platform feature on your Windows
  4. Enable Windows Subsystem for Linux (WSL) feature on your Windows
  5. Installing Ubuntu 20.04 LTS in Windows Subsystem
  6. Optional: Installing Ubuntu 20.04 in WSL 2 Using Powershell Command Prompt
  7. Configure Ubuntu User Account and Password

Step 1. Check your version and build number on Windows

To check your version and build number on Windows 10 to determine the compatibility of your system with the Windows Subsystem for Linux (WSL) feature, you can follow these steps:

  1. Open the PowerShell command prompt.
  2. Type the following command and press Enter:
systeminfo | findstr /B /C:"OS Name" /C:"OS Version"

The output should show your Windows version and build number, which you can then compare against the minimum requirements for WSL.

How to Install Ubuntu 20.04 in WSL2 on a Windows 10

Note: The minimum requirements for WSL are Windows 10 version 1709 or later, with build number 16299 or later.

Step 2. Check if your user has administrator privileges on a Windows

Use the PowerShell command prompt to check if your user has administrator privileges on a Windows 10 machine:

whoami /groups

The output will show a list of the groups that your user belongs to. If you see S-1-5-32-544 listed, it means that your user has administrator privileges.

If your user does not have administrator privileges, you can either log in as an administrator or ask an administrator to elevate your privileges to perform administrative tasks.

Step 3. Enable the Windows Machine Platform feature on your Windows

Windows Machine Platform features are required to run Windows Subsystem for Linux (WSL2). In order to use WSL2, the Windows Machine Platform features must be enabled on your Windows 10 machine.

Enable the Windows Machine Platform features using the PowerShell command prompt.

  1. Open the PowerShell command prompt as an administrator.
  2. Run the following command:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
  1. Restart your machine to complete the installation.

Step 4. Enable Windows Subsystem for Linux (WSL) feature on your Windows

Check if the Windows Subsystem for Linux (WSL) feature is enabled on your system using the following command in PowerShell:

dism.exe /online /get-features | Where-Object { $_ -match "Microsoft-Windows-Subsystem-Linux" }

Check the output for the “Feature Name: Microsoft-Windows-Subsystem-Linux“. If it shows, the Windows Subsystem for Linux (WSL) feature is enabled on your system. If the feature is not enabled, the output will not display any information about it.

To enable the Windows Subsystem for Linux (WSL) feature on your Windows 10 machine using the command line, you can run the following command in PowerShell:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

Here’s what each part of the command does:

  • dism.exe is the Deployment Image Servicing and Management (DISM) tool, which is used to manage and modify the system image.
  • /online specifies that the operation should be performed on the running system, rather than an offline image.
  • /enable-feature enables a specific feature on the system.
  • /featurename:Microsoft-Windows-Subsystem-Linux is the feature being enabled, which is the Windows Subsystem for Linux.
  • /all specifies that all parent features of the specified feature should also be installed.
  • /norestart prevents the system from being restarted after the feature has been installed.

To verify in the console, make sure both WSL2 features are enabled:

How to Install Ubuntu 20.04 in WSL2 on a Windows 10

Step 5. Installing Ubuntu 20.04 LTS in Windows Subsystem

Once the WSL feature has been enabled, you can install one or more Linux distributions from the Microsoft Store or by using the wsl command. To install Ubuntu 20.04 LTS in the windows console, use these steps:

  1. Open the Microsoft Store and search for “Ubuntu 20.04”.
  2. Click on the “Ubuntu 20.04” app and click the “Get” button to download and install it.
  3. Once the installation is complete, click the “Launch” button to open a terminal for Ubuntu 20.04, or open the Ubuntu 20.04 LTS distribution by searching from the “Start menu”.
How to Install Ubuntu 20.04 in WSL2 on a Windows 10

Step 6. Optional: Installing Ubuntu 20.04 in WSL 2 Using Powershell Command Prompt

Otherwise, use the PowerShell command prompt to install Ubuntu 20.04 LTS in WSL 2 on a Windows 10 machine with the following commands:

  1. wsl --list --online: Lists the valid WSL distributions that can be installed.
  2. wsl --install -d Ubuntu-20.04: Installs the Ubuntu 20.04 LTS distribution in WSL 2.
  3. wsl --set-default-version 2: Sets WSL 2 as the default version for future WSL installations.
  4. wsl -l -v: Lists the installed WSL distributions and their version numbers.
  5. wsl --list: Lists the installed WSL distributions and their status.
  6. lsb_release -a: To displays the version information of the installed Ubuntu 20.04 LTS distribution.

Step 7. Configure Ubuntu User Account and Password

Once you have followed these steps, you will have successfully installed Ubuntu 20.04 LTS in WSL 2 on your Windows 10 machine. Then run the ubuntu2004 command in the PowerShell command prompt, it will launch the Ubuntu 20.04 LTS distribution.

If you have not created a user account, you will be prompted to create one, and will see the following output:

Creating new user account...
username:

You will then be prompted to enter a username for the new user account, after which you will be prompted to enter a password.

If you have already created a user account, you will see the following output:

Welcome to Ubuntu 20.04 LTS (GNU/Linux 4.19.104-microsoft-standard x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

0 packages can be updated.
0 updates are security updates.


The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

username@Ubuntu:~$

Finally, I would recommend updating and upgrading Ubuntu using the following commands before moving to the next steps.

sudo apt update
sudo apt full-upgrade

Troubleshooting Windows Subsystem for Linux: https://learn.microsoft.com/en-us/windows/wsl/troubleshooting

Conclusion

In conclusion, installing Ubuntu 20.04 in WSL2 on Windows 10 is a quick and easy process that provides a lot of benefits. It gives you the ability to use Linux on a Windows machine without the overhead of a virtual machine, making it a great choice for developers and Linux enthusiasts.

I hope this blog has helped you. Feel free to leave a comment in the section below for further recommendation

Visit Related Blog: How to install Visual Studio and Connect to Linux Ubuntu 20.04 in WSL2

SHARE THIS ARTICLE

Tags: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *