WSL 2 and Ubuntu - Windows

As a budding developer, you started with simple, straightforward tools to build your foundational skills. Now, it's time to elevate your development environment by transitioning to WSL 2 (Windows Subsystem for Linux). This upgrade provides a more powerful, flexible environment, enabling you to tackle advanced projects with confidence.

Why Choose WSL 2?

Think of WSL 2 as having the best of both worlds: the power of Linux combined with the familiarity of Windows. It offers:

It's like adding a powerful new engine to a car you're already comfortable driving, making it faster and more efficient.

Step-by-Step Guide to Setting Up WSL 2

  1. Check Computer Requirements

    Ensure your system supports WSL 2:

    1. Press Windows + R, type winver, and press Enter.
    2. For Windows 10:
      • x64: Version 1903 or higher
      • ARM: Version 2004 or higher
    3. Check system type: Open PowerShell and run systeminfo | find "System Type".
    4. For Windows 11, WSL 2 is already supported.

    To install WSL, open PowerShell as an administrator and run wsl --install. Restart your computer when prompted.

  2. Enable WSL and Virtual Machine Features

    Run the following commands in PowerShell as an administrator:

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

    Restart your computer.

  3. Download the Linux Kernel Update Package

    Based on your system type (x64 or ARM), download and install the appropriate Linux kernel update package. Use the systeminfo command if you're unsure of your system type.

  4. Set WSL 2 as Default

    In PowerShell, run wsl --set-default-version 2.

  5. Install Your Linux Distribution

    From the Microsoft Store, search for and install a Linux distribution such as Ubuntu 22.04.3 LTS. Upon launching, complete the setup:

    • Provide a UNIX username (lowercase, no spaces).
    • Set and confirm a password.

    Update your system using:

    sudo apt update && sudo apt upgrade

  6. Set Default Distribution

    If you installed multiple distributions, set your default using:

    wsl --list
                        wsl --setdefault 
  7. Configure Git

    Set up Git in Ubuntu:

    git config --global user.name ""
    git config --global user.email ""
    git config --global init.defaultBranch main

    Verify your configuration with git config --list.

  8. Install nvm, Node.js, and Mocha

    Install nvm:

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

    Update your shell configuration by adding:

    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \.
    [ -s "$NVM_DIR/bash_completion" ] && \.

    Install Node.js:

    nvm install 18

    Install Mocha:

    npm -g install mocha

Real-World Applications and Benefits

WSL 2 is ideal for developers transitioning into more advanced workflows. Whether you're running Docker containers, testing server-side code, or exploring Linux-exclusive tools, WSL 2 bridges the gap between Windows and Linux, allowing for seamless development.

Think of it as upgrading from a basic toolkit to a professional-grade workshop, enabling you to tackle projects with precision and efficiency.

Further Learning

Explore these topics to deepen your understanding: