How to Install Ubuntu in WSL2 in Just 3 Steps

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The WSL (Windows Subsystem for Linux) feature allows a user to install a Linux distro and execute Linux commands in Windows. WSL 2 is the current version of WSL which uses the latest and greatest virtualization technology. It has faster file system performance, is more compatible, and uses a real Linux kernel. In this article, I will show how to install Ubuntu in WSL2. Furthermore, follow this article if you want to know how to install Ubuntu in WSL 1.

To install Ubuntu in WSL2, follow the steps below:

  1. Enable WSL in Windows
  2. Make WSL 2 Default
  3. Install Ubuntu in WSL 2

Requirements to Install Ubuntu in WSL2

  • Windows Operating System.
  • Command Prompt.
  • Stable Internet Connection.

Process Flow Chart to Install Ubuntu in WSL2:Process flow chart for "wsl2 install ubuntu"[OS Used Throughout the Tutorial: Windows 11]

3 Steps to Install Ubuntu in WSL 2

This is the core part of this article where I will show how to install Ubuntu in WSL2 in 3 simple steps.

Step 01: Enable WSL in Windows

In the beginning, I will enable the WSL feature in my Windows Operating system. You can do the same by following these steps:

  1. Search Command Prompt, left-click on the mouse, and select “Run as administrator” to open it as administrator.Opening Command Prompt
  2. To enable WSL, insert the following command and hit ENTER:
    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
    EXPLANATION
    • exe: Services Windows images, such as updating, adding or removing features.
    • /online: Specifies that the command should be applied to the running operating system.
    • /enable-feature: Enables a specific Windows feature.
    • /featurename:Microsoft-Windows-Subsystem-Linux: Name of the feature being enabled.
    • /all: Enables all the parent features of the specified feature.
    • /norestart: Prevents the computer from automatically restarting after the feature is installed.
    Enabling WSL2 for "wsl2 install ubuntu"Wait for 100% and the “The operation completed successfully” message at the end.
  3. Again, to enable Virtual Machine Platform, insert the following command and hit ENTER:
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
    EXPLANATION
    • exe: Services Windows images, such as updating, adding or removing features.
    • /online: Specifies that the command should be applied to the running operating system.
    • /enable-feature: Enables a specific Windows feature.
    • /featurename:VirtualMachinePlatform: Name of the feature being enabled.
    • /all: Enables all the parent features of the specified feature.
    • /norestart: Prevents the computer from automatically restarting after the feature is installed.
    Enabling Virtual Machine PlatformLike the previous, you will see 100% and the “The operation completed successfully” message. This process will enable the Virtual Machine Platform feature which allows users to run virtual machines natively on Windows.
  4. Then restart the computer.

Step 02: Make WSL 2 Default

Now I will make WSL 2 the default WSL version, which means Linux distros will be installed on WSL 2 by default:

  1. To make WSL 2 default, write the following command in the Command Prompt:
    wsl --set-default-version 2
    EXPLANATION
    • wsl: Manages WSL.
    • –set-default-version: Sets default WSL version.
    • 2: The WSL version number.
  2. Press ENTER from the keyboard.Setting WSL 2 as default WSL version You should see an output like the above.

Step 03: Install Ubuntu in WSL 2

Finally, I will install Ubuntu in WSL. You can do the same by following the steps below:

  1. At first, use the following command to list all the available Linux distros:
    wsl --list --online
    EXPLANATION
    • wsl: Manages WSL.
    • –list: Lists installed or available distros.
    • –online: Lists only those distros which can be downloaded online.
    Listing available Linux DistrosYou will see two columns, the name of the Linux distro and its corresponding friendly name. I will install “Ubuntu-22.04” in the next step.
  2. To install Ubuntu, copy the following command:
    wsl --install -d Ubuntu-22.04
    EXPLANATION
    • wsl: Manages WSL.
    • –install: Install a new Linux distro.
    • -d: Specify that you are installing a distribution.
    • Ubuntu-22.04: Name of the distro that is being installed.
  3. Give a username for the Ubuntu.
  4. Finally, set a password.Installing Ubuntu You should remember that this whole process can take some time. In the end, you should see an Ubuntu shell where you can execute Linux commands.
    Warning: If you face any issue while installing Linux distribution, check the WSL status using:

    wsl --status

    If, this happens due to the WSL kernel being missing then run:

    wsl --update
    This should solve the issue.

    wsl 2 kernel missing solution

  5. (Optional) Now execute the following command to print installed Linux distros and their corresponding version:
    wsl --list --verbose

    OR

    wsl -l -v
    EXPLANATION
    • wsl: Manages WSL.
    • -l,–list: LIsts distros that are currently installed.
    • -v,–verbose: Shows additional information.
    Listing installed Linux DistrosAs you can see, the WSL version is 2. Therefore, Ubuntu is successfully installed in WSL 2.
  6. Now you should find Ubuntu in your Windows like below:Finding Ubuntu in Windows

Conclusion

In this article, I have shown how to install Ubuntu in WSL2 in three steps. However, remember, step 2 might not be necessary as WSL 2 is the default WSL version in Windows mostly. Finally, I hope this article was helpful to you.

People Also Ask

How to access Ubuntu after installation using WSL2?

To access Ubuntu after installation via WSL2, go to the Start menu and open Ubuntu from there since Windows adds Ubuntu to its menu when installing. This is also applicable to access whichever Linux you choose during installation.

What is the best Linux distro for WSL2?

Ubuntu is the best Linux distro for WSL. It is a user-friendly and well-supported distro, with a large community and documentation. It comes with WSL2 by default and you can download it from the Microsoft Store and “wsl –install” command.

How to enable WSL2 and “Virtual machine Platform” using the Windows GUI (Graphical User Interface)?

To enable WSL2 and the “Virtual Machine Platform” using the GUI provided by your Windows OS, first, go to the Windows Start menu and type “turn on Windows features”. Secondly, select “Windows Subsystem for Linux” and “Virtual Machine Platform”. Finally, click OK and restart your PC.

Can I run VirtualBox in WSL2?

It is possible to run VirtualBox in WSL2. However, you must use Windows 10 (21H2) or higher, enable Hypervisor Platform, and use VirtualBox 6.1.4 or newer.

How to display the Ubuntu GUI desktop application via WSL?

To display the Ubuntu GUI desktop application via WSL:

  1. Install Ubuntu desktop using sudo apt install ubuntu-desktop
  2. Install an X server, for example, VcXsrv, from the official website.
  3. Configure the X server.
  4. Set a display environment variable.
  5. Start the Ubuntu desktop environment.

Can I convert Ubuntu on WSL1 to WSL2?

Yes, you can. To convert an existing WSL1 Ubuntu distro to WSL2, open the Windows PowerShell and run the command ws.exe --set-version Ubuntu 2 (replace the name Ubuntu with whichever Linux distro you choose). Additionally, you might restart your computer to ensure that the changes take effect.

Related Articles


<< Go Back to Windows Subsystem for Linux | Linux OS Single InstallationLearn Linux Basics

4.9/5 - (8 votes)
Walid Al Asad

Hello Everyone! I am Walid Al Asad. Currently, I am working at a tech company named Softeko as a Linux Content Developer Executive. I live in Dhaka, Bangladesh. I have completed my BSc. in Mechanical Engineering from Bangladesh University of Engineering and Technology (BUET). You can find me on LinkedIn, and ResearchGate. Read Full Bio

5 thoughts on “How to Install Ubuntu in WSL2 in Just 3 Steps”

  1. Unfortunately it all broke down at step 3 . There was no user name or password input in the command lines . Could not proceed . A really nice explanation up to that point .

    Reply

Leave a Comment