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. In addition, you can see this article to know how to install Ubuntu in WSL using GUI.
Key Takeaways
- Enabling the WSL feature in Windows.
- Making WSL 2 the default WSL version.
- Installing Ubuntu in WSL 2.
Requirements
- Windows Operating System.
- Command Prompt.
- Stable Internet Connection.
Process Flow Chart
[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 three simple steps.
Step 01: Enable WSL in Windows
In the beginning, I will enable the WSL feature in my Windows by the following steps.
Steps to Follow >
- Search Command Prompt, left-click on the mouse and select “Run as administrator” to open it as administrator.
- 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.
Wait for 100% and the “The operation completed successfully” message at the end.
- 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.
Like 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.
- 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.
Steps to Follow >
- 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.
- Press ENTER from the keyboard.
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:
Steps to Follow >
- 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.
You 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.
- To install Ubuntu, copy the following command:
wsl --install Ubuntu-22.04
EXPLANATION- wsl: Manages WSL.
- –install: Installs a new Linux distro.
- Ubuntu-22.04: Name of the distro which is being installed.
- Give a username for the Ubuntu.
- Finally, set a password.
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.
- (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.
As you can see, the WSL version is 2. Therefore, Ubuntu is successfully installed in WSL 2.
- Now you should find Ubuntu in your Windows like below.
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
Related Articles