How to Install Windows Subsystem for Linux (WSL) and Run the Ubuntu Subsystem on Windows Using the Terminal
Divyansh Tiwari
Posted on August 10, 2024
If you've ever wanted to run Linux on your Windows computer, you're in the right place! In this blog, I'll guide you through the simple process of installing the Windows Subsystem for Linux (WSL) and getting the latest Ubuntu subsystem up and running—all from the terminal. By the end of this tutorial, you'll be able to use Ubuntu directly from your Windows machine. Let's get started!
Step 0: Prepare Your Windows for WSL Installation
Before we dive into enabling WSL and installing Ubuntu, you need to make sure certain features are enabled on your Windows machine. These features are essential for WSL to function correctly.
Open Windows Features:
- Right-click on the Taskbar and select Taskbar settings.
- In the Taskbar settings window, click on Search from the left-hand menu.
- In the search bar, type "optional features" and press Enter.
- Scroll down and click on More Windows features. This will open the Windows Features dialog box.
Enable Required Features:
In the Windows Features dialog box, scroll down and check the following three options:
Virtual Machine Platform
Windows Subsystem for Linux
Windows Hypervisor Platform
These features are essential for running WSL and the Ubuntu subsystem. Make sure all three are checked.
Apply Changes and Restart:
- After selecting the necessary features, click OK.
- Windows will take a few moments to apply these changes. Once completed, you'll be prompted to restart your computer. Go ahead and do that.
- Note: Restarting your computer is important to ensure that the changes take effect properly.
Once your computer has restarted, you're ready to proceed with the WSL installation steps.
Step 1: Enable Windows Subsystem for Linux (WSL)
With the necessary features enabled, you can now proceed to enable WSL on your Windows machine. Here’s how to do it:
- Open PowerShell as Administrator:
- Click on the Start Menu.
- Type "PowerShell".
- Right-click on Windows PowerShell and select Run as administrator.
- Enable WSL:
In the PowerShell window, type the following command and press Enter:
wsl --install
- This command will enable WSL and install the default Linux distribution, which is typically Ubuntu.
- If you already have WSL installed but not enabled, use this command instead:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
- Wait for the process to complete. You might be asked to restart your computer. Go ahead and do that.
Step 2: Check the Version of WSL
After restarting, it’s important to check which version of WSL you have installed, as WSL 2 offers more features and better performance.
- Check WSL Version:
- Open a new PowerShell window (you don’t need administrator rights for this).
- Type the following command and press Enter:
wsl --list --verbose
- This command will show you the version of WSL that is currently installed on your machine.
- If WSL 1 is installed and you want to upgrade to WSL 2, follow these steps:
- Ensure you’re running Windows 10, version 1903 or higher, with Build 18362 or higher.
- Install the WSL 2 Linux kernel update package by downloading it from the Microsoft website.
- In PowerShell, set WSL 2 as the default version by running:
wsl --set-default-version 2
- You can then convert any existing WSL 1 distributions to WSL 2 with the following command:
wsl --set-version <distro name> 2
- Replace with the name of your installed Linux distribution (e.g., Ubuntu).
Step 3: Install Ubuntu Using the Terminal
Now that WSL is enabled and configured, it's time to install the Ubuntu distribution directly from the terminal.
- List Available Distributions:
- In the PowerShell or Command Prompt, type the following command to see a list of available Linux distributions:
wsl --list --online
- This will show you all the Linux distributions you can install, including various versions of Ubuntu.
- Install Ubuntu:
- To install the latest version of Ubuntu, use the following command:
wsl --install -d Ubuntu
If you want to install a specific version of Ubuntu, replace Ubuntu with the exact name from the list you obtained in the previous step (e.g., Ubuntu-20.04).
The installation will begin, and this may take a few minutes depending on your internet connection and system performance.
Step 4: Set Up Ubuntu
After Ubuntu is installed, you’ll need to complete the initial setup.
- Launch Ubuntu:
- After the installation is complete, Ubuntu will launch automatically, or you can start it manually by typing wsl in the terminal or by searching for "Ubuntu" in the Start Menu and opening it.
- Create a User Account:
The first time you launch Ubuntu, it will ask you to create a user account and set a password.
Follow the on-screen instructions to set up your username and password. Remember this information, as you'll need it to log in.
Step 5: Update and Upgrade Ubuntu
With Ubuntu set up, it's a good idea to update the system to ensure you have the latest software and security patches.
- Open the Terminal:
- You should already be in the Ubuntu terminal, but if not, just open the Ubuntu app from the Start Menu or by typing wsl in PowerShell or Command Prompt.
- Update Package Lists:
- Type the following command and press Enter:
sudo apt update
- Upgrade Installed Packages:
- After the package lists are updated, upgrade your installed packages with:
sudo apt upgrade -y
- This command will upgrade all the installed software to the latest versions. The -y flag automatically agrees to the installation of updates.
Step 6: Start Using Ubuntu on Windows
Congratulations! You now have Ubuntu running on your Windows machine. You can use the terminal to run Linux commands, install additional software, and even use it for development tasks.
Bonus: Setting WSL 2 as the Default for All Future Installations
To ensure all future Linux distributions installed via WSL are set to use WSL 2 by default, you can run the following command:
wsl --set-default-version 2
This ensures you always get the best performance and features available in WSL 2.
Conclusion
That's it! You've successfully installed the Windows Subsystem for Linux and set up the Ubuntu subsystem on your Windows machine—all using the terminal. Now you can enjoy the power of Linux right alongside your favorite Windows apps. Whether you're a developer, a Linux enthusiast, or just curious, WSL is a fantastic tool to have in your toolbox.
If you found this guide helpful, be sure to share it with others who might benefit from running Linux on Windows. Happy coding!
Posted on August 10, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.