Search This Blog

21 March, 2022

How to Set Up the Linux Subsystem for Windows and Install Ubuntu

How to Set Up the Linux Subsystem for Windows and Install Ubuntu

Installing the Windows Subsystem for Linux (WSL) allows you to run a Linux environment directly on Windows without the need for a separate virtual machine or dual-boot setup. This can be particularly useful for developers, system administrators, and anyone interested in learning Linux. Follow these steps to set up WSL and install Ubuntu.

Why Use WSL?

  1. Seamless Integration: WSL enables you to run Linux command-line tools alongside your Windows applications, providing a powerful combination of both operating systems. You can easily share files between Windows and Linux, making development workflows more efficient.

  2. Access to Linux Tools: Many developers prefer Linux for programming, scripting, and system management tasks due to its rich ecosystem of command-line tools and package managers. With WSL, you can use popular tools like Git, SSH, and various programming languages without leaving your Windows environment.

  3. Development Environment: If you’re working on web development, cloud computing, or data science, WSL allows you to set up a Linux-based development environment quickly. You can run servers, databases, and applications as if you were on a native Linux system.

  4. Learning Linux: For those new to Linux, WSL provides a safe environment to learn and experiment without needing to leave your primary operating system. It’s an excellent stepping stone for transitioning to full-time Linux use or simply gaining familiarity with the command line.

Step-by-Step Installation

Step 1: Check Your WSL Version

First, let’s determine which version of WSL you have installed. Open PowerShell as an administrator and run:

wsl --list --verbose

Expected Output (if WSL is installed):

NAME STATE VERSION * Ubuntu Running 2

If WSL is not installed, you may see an error message indicating that WSL is not recognized.

Step 2: Enable the Windows Subsystem for Linux

Run the following command to enable the Windows Subsystem for Linux feature:

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

Expected Output:

Deployment Image Servicing and Management tool Version: 10.0.19041.1 Image Version: 10.0.19041.1 Enabled feature(s): - Microsoft-Windows-Subsystem-Linux

Step 3: Enable the Virtual Machine Platform

Next, enable the Virtual Machine Platform, which is necessary for setting up WSL 2:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Expected Output:

Deployment Image Servicing and Management tool Version: 10.0.19041.1 Image Version: 10.0.19041.1 Enabled feature(s): - VirtualMachinePlatform

Step 4: Reboot Your System

After enabling these features, reboot your system:

Restart-Computer -Force

This command will force a restart of your computer.

Step 5: Download and Install the WSL 2 Kernel

Download and install the WSL 2 kernel from the following link:
Download WSL 2 Kernel

Follow the on-screen instructions to install the kernel update.

Step 6: Set WSL 2 as the Default Version

Once your system has restarted, open PowerShell as an administrator again and run the following command to set WSL 2 as your default version:

wsl --set-default-version 2

Expected Output:

The default version has been set to 2.

For more information on the key differences between WSL 1 and WSL 2, visit: WSL 2 Information

Step 7: List Available Distributions

To view a list of available distributions, use the following command:

wsl --list --online

Expected Output:

Available distributions: Ubuntu-20.04 Ubuntu-22.04 Debian Kali-Linux Alpine ... To install a distribution, use the command: wsl --install -d <Distro>

Step 8: Install Ubuntu

To install Ubuntu, run:

wsl --install -d Ubuntu-22.04

Note: Replace Ubuntu-22.04 with your preferred version if needed.

Expected Output (during installation):

Downloading and installing... ... Installing, this may take a few minutes.

After installation, you will see:

Installation successful!

Step 9: Start Ubuntu

To start Ubuntu, simply type:

wsl

This command will launch Ubuntu and log you in as the root user.

Alternatively, you can type:

ubuntu

You can also find a shortcut to Ubuntu in the Start menu. Clicking this shortcut will open the Ubuntu Bash shell.

Conclusion: The Importance of Linux Today

Linux continues to be an essential part of the technology landscape for several reasons:

  1. Open Source and Collaboration: As an open-source operating system, Linux encourages collaboration and innovation. This community-driven approach results in a robust, flexible platform that can be customized for various needs, from embedded systems to cloud servers.

  2. Server and Cloud Dominance: A significant portion of the world’s servers run on Linux, making it a crucial player in cloud computing and web hosting. Its stability, security, and performance make it the preferred choice for many enterprises.

  3. Development and DevOps: Linux is at the forefront of software development and DevOps practices. Its compatibility with various programming languages and tools makes it an ideal environment for developers, particularly in building, testing, and deploying applications.

  4. Emerging Technologies: As technologies like artificial intelligence, machine learning, and blockchain continue to evolve, Linux remains a central player. Many frameworks and tools in these areas are optimized for Linux, making it a vital platform for research and development.

  5. Security and Privacy: Linux is often considered more secure than other operating systems. Its open-source nature allows for continuous scrutiny and improvement, leading to a more secure environment for users and organizations.

By setting up WSL and installing Ubuntu, you’re not just enhancing your personal workflow; you’re also tapping into the vast potential of Linux in today’s tech landscape. Embracing Linux can open doors to new opportunities and empower you to tackle challenges with confidence.