A Comprehensive Guide to Enabling WSL2 on Windows and Setting Up Docker Desktop

Welcome, fellow tech enthusiasts! Whether you're a seasoned developer or just starting out, today we’re diving into the wonderful world of Windows Subsystem for Linux (WSL) and Docker Desktop. We’ll walk through enabling WSL2, downloading Ubuntu’s latest distro, and setting up Docker Desktop for a seamless development experience. So grab your favorite beverage, and let’s get started!

What is WSL2?

WSL2 (Windows Subsystem for Linux version 2) is a compatibility layer that allows you to run a Linux environment directly on Windows without the overhead of a traditional virtual machine. With WSL2, you can enjoy the benefits of Linux tools and utilities right alongside your Windows applications.

Why WSL2?

  • Performance: WSL2 uses a real Linux kernel, offering significant performance improvements over WSL1.

  • Compatibility: Run more applications that rely on Linux kernel features.

  • Integration: Seamlessly access files across both environments.

Step 1: Enable Virtualization on Your Computer

Before we install WSL2, we need to make sure that virtualization is enabled on your computer. This is usually enabled by default, but it’s worth checking!

For Windows:

  1. Access BIOS/UEFI: Restart your computer and enter the BIOS/UEFI setup (usually by pressing F2, Del, or Esc during boot).

  2. Find Virtualization Settings: Look for options like “Intel VT-x,” “Intel Virtualization Technology,” or “AMD-V.”

  3. Enable it: Change the setting to “Enabled.”

  4. Save and Exit: Save your changes and reboot.

For Linux:

  1. Check if Virtualization is Enabled: Open a terminal and run:

     lscpu | grep Virtualization
    

    You should see either "VT-x" (Intel) or "AMD-V" (AMD).

  2. If it’s not enabled, follow similar BIOS steps as above.

For Mac:

On Mac, virtualization is typically enabled by default. Just make sure you’re running an updated version of macOS.

Step 2: Enable WSL and Install WSL2

Now that virtualization is enabled, let’s install WSL2.

For Windows 10/11:

  1. Open PowerShell as Administrator: Right-click on the Start menu and select “Windows PowerShell (Admin).”

  2. Enable WSL:

     wsl --install
    
  3. Set WSL2 as your default version:

     wsl --set-default-version 2
    
  4. Download Ubuntu: You can install the latest Ubuntu version directly from the Microsoft Store. Simply search for “Ubuntu” and click “Install.”

  5. Set Up Ubuntu: Once installed, launch Ubuntu from the Start menu and follow the prompts to set up your user account.

For Linux/Mac:

If you’re on a Linux or Mac system, you won’t use WSL but can use Docker Desktop directly. We’ll cover Docker setup next.

Step 3: Install Docker Desktop

Docker Desktop is an essential tool for managing containers, and it integrates beautifully with WSL2.

For Windows:

  1. Download Docker Desktop: Go to the Docker Desktop website and download the installer.

  2. Run the Installer: Follow the installation instructions. During the installation, ensure that the option for WSL integration is enabled.

  3. Launch Docker Desktop: Once installed, open Docker Desktop.

  4. Enable WSL Integration:

    • Go to Settings > Resources > WSL Integration.

    • Toggle on the integration for your installed WSL distros (like Ubuntu).

  5. Test Your Setup: Open a new terminal in Ubuntu and run:

     docker --version
    

    This should show you the installed version of Docker.

For Linux:

  1. Install Docker: Open a terminal and run the following commands based on your distribution:

  2. Start Docker:

     sudo systemctl start docker
     sudo systemctl enable docker
    
  3. Verify Installation:

     docker --version
    

For Mac:

  1. Download Docker Desktop: Go to the Docker Desktop website and download the macOS version.

  2. Install Docker: Drag Docker into your Applications folder and launch it.

  3. Enable WSL Integration (if necessary): Docker on Mac doesn’t require WSL, but it’s good to ensure Docker is set up properly.

Conclusion

Congratulations! You’ve successfully enabled WSL2, installed the latest Ubuntu distro, and set up Docker Desktop for development. You now have a powerful environment for building and managing your applications, seamlessly integrating the best of Windows and Linux.

Final Thoughts

Keep exploring the vast world of Linux tools and Docker containers. The sky's the limit when it comes to what you can create! And if you run into any hiccups, remember: the tech community is here to help, and so am I! Happy coding!