How to Install Ubuntu on WSL 2: A Comprehensive Guide

How to Install Ubuntu on WSL 2: A Comprehensive Guide

The Windows Subsystem for Linux (WSL 2) has completely changed the game for developers. It allows you to run a full Linux kernel alongside your Windows OS, giving you the best of both worlds: the familiar Windows interface and the powerful command-line tools of Ubuntu.

If you’ve been looking for a way to use Linux without the overhead of a virtual machine or the complexity of dual-booting, this guide is for you.

Why Choose WSL 2?

Unlike the original WSL, which translated Linux system calls into Windows calls, WSL 2 uses a real Linux kernel in a lightweight utility VM. This results in:

  • Full System Call Compatibility: Run complex apps like Docker or databases natively.
  • Faster File System Performance: Significantly quicker execution when working with Linux-based files.
  • Seamless Integration: Access your Windows files from Linux and vice versa.

Pre-installation Checklist

Before we dive into the installation, make sure your system is ready:

  1. OS Version: You need Windows 10 (Version 1903, Build 18362 or higher) or Windows 11.
  2. BIOS/UEFI Settings: Virtualization must be enabled in your computer’s BIOS settings.
  3. Updates: Ensure your Windows installation is up to date via Windows Update.

To check your Windows version: Press Win + R, type winver, and hit Enter.

Step 1: Enable WSL Features

The Quick Method (Recommended)

For most modern Windows versions, you can enable everything with a single command.

  1. Open PowerShell as an Administrator, Search for “PowerShell” in the Start Menu (Right-click -> Run as Administrator).
  2. Run: wsl --install
  3. Restart your computer. This step is mandatory to apply the feature changes.

The Manual Method (For Older Builds)

If the command above doesn’t work, you can enable the features manually:

  1. Open PowerShell as Administrator and run:
    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  2. Set WSL 2 as the default version:
    wsl --set-default-version 2
  3. Restart your computer.

Step 2: Installing Your Ubuntu Distribution

You have two main ways to install the Ubuntu OS itself.

Method A: Via Command Line

  1. Open PowerShell as Administrator.
  2. List available distributions:
    wsl --list --online This command displays a list of available Linux distributions.The following is a list of valid distributions that can be installed. The default distribution is denoted by ‘*’. Install using ‘wsl –install -d ‘.
    NAME FRIENDLY NAME
    Ubuntu Ubuntu
    Debian Debian GNU/Linux
    kali-linux Kali Linux Rolling
    Ubuntu-18.04 Ubuntu 18.04 LTS
    Ubuntu-20.04 Ubuntu 20.04 LTS
    Ubuntu-22.04 Ubuntu 22.04 LTS Ubuntu-24.04 Ubuntu 24.04 LTS
  3. Install your desired Ubuntu version (e.g., Ubuntu 24.04 LTS): wsl --install -d Ubuntu-24.04
  4. You’ll see an indicator of the installation progress in the terminal:
    Installing: Ubuntu 24.04 LTS [==========================72,0%========== ]
  5. Use wsl -l -v to see all your currently installed distros and the version of WSL that they are using:NAME STATE VERSION Ubuntu-20.04 Stopped 2 * Ubuntu-24.04 Stopped 2
  6. Upon completion, Ubuntu will launch, prompting you to create a UNIX username and password.

Method B: Via Microsoft Store

  1. Open the Microsoft Store and search for “Ubuntu”.
  2. Select the version you want (the latest LTS version is usually best for stability).
  3. Click Get or Install.

Step 3: Initial Setup and Configuration

Once the installation finishes, the Ubuntu terminal will open automatically.

  1. Create a User: You will be prompted to enter a UNIX username and password. (Note: This is separate from your Windows credentials).
  2. Verify the Version: Ensure you are running on the WSL 2 architecture. In PowerShell, run: wsl --list --verbose If the version shows ‘1’, you can upgrade it with: wsl --set-version Ubuntu-24.04 2.

Step 4: Post-Installation Best Practices

The first thing you should always do in a fresh Ubuntu install is update the package list and upgrade existing software:

sudo apt update && sudo apt upgrade -y

Pro Tip: Accessing Files Across Systems

  • Windows files from Ubuntu: Navigate to /mnt/c/Users/YourName/.
  • Ubuntu files from Windows: Open File Explorer and type \\wsl$ in the address bar.

Conclusion

Setting up Ubuntu on WSL 2 provides a robust development environment right on your Windows machine. Whether you’re a web developer, a data scientist, or just someone looking to learn Linux, WSL 2 is the most efficient way to get started.


Discover more from TCMHACK

Subscribe to get the latest posts sent to your email.

Tags:

Leave a Reply

Discover more from TCMHACK

Subscribe now to keep reading and get access to the full archive.

Continue reading