Windows Subsystem for Linux (WSL): A Step-by-Step Guide

Solution: Setting Up WSL 2 for Seamless Development

Windows Subsystem for Linux (WSL) allows developers and IT teams to run a Linux environment—like Ubuntu—natively on Windows, combining the best of both worlds. WSL 2, the latest version, offers improved performance and full Linux kernel compatibility, making it ideal for business automation, cloud migration, and IT infrastructure solutions. Below is a step-by-step guide to set up WSL 2, along with an automated script to save time, based on 1it.pro’s proven DevOps services approach.

Step 1: Enable Windows Features for WSL 2

To get started, you need to enable the necessary Windows features. Open PowerShell as an administrator (Win + X → "Windows PowerShell (Admin)") and run:

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

Restart your computer to apply these changes. This step prepares your system for WSL 2’s lightweight virtualization.

Step 2: Install WSL 2 and Update the Linux Kernel

  1. Download the Linux kernel update package for WSL 2.

  2. Run the installer and follow the prompts to complete the setup.

  3. Set WSL 2 as the default version by running:

    wsl --set-default-version 2
    

This ensures all new Linux distributions use WSL 2’s enhanced performance.

Step 3: Install a Linux Distribution

  1. Open the Microsoft Store and search for a Linux distribution, such as Ubuntu (a popular choice for its versatility).
  2. Click Install and wait for the download to complete.

Step 4: Configure Your Linux Distribution

  1. Launch the installed distribution from the Start menu.
  2. On first launch, set up a UNIX username and password. This creates your Linux user account.
  3. Your Linux environment is now ready to use.

Step 5: Update and Install Essential DevOps Tools

To make your Linux environment production-ready, update the system and install key tools for DevOps services and business automation. In the Linux terminal, run:

sudo apt update && sudo apt upgrade -y

Next, install essential utilities for development and IT operations:

sudo apt install -y vim htop telnet ansible mc git python3 python3-pip pipx docker.io docker-compose jq unzip

Pro Tip from 1it.pro: These tools are critical for automating workflows, managing containers, and integrating with platforms like n8n automation for streamlined process optimization.

Step 6: Install Cloud and Infrastructure Tools

For businesses leveraging cloud solutions, tools like AWS CLI and Terraform are essential. Install them as follows:

AWS CLI:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

Terraform:

curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install -y terraform

These tools enable cloud migration and Infrastructure as Code (IaC), aligning with 1it.pro’s expertise in scalable IT solutions.

Step 7: Enhance Productivity with Windows Terminal

For a seamless experience, install Windows Terminal from the Microsoft Store. This modern interface allows you to access your Linux distribution, PowerShell, and Command Prompt in one place, boosting productivity for IT teams.

Automating WSL 2 Setup with PowerShell

Manual setup is fine for one machine, but businesses with multiple workstations need efficiency. At 1it.pro, we automate repetitive tasks to save time. Below is a PowerShell script to automate WSL 2 and Ubuntu installation:

# PowerShell Script for Automated WSL 2 and Ubuntu Setup

Write-Output "Enabling WSL and Virtual Machine Platform features..."
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -All -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -All -NoRestart

# Check if reboot is required
if ($LASTEXITCODE -eq 3010) {
    Write-Output "Reboot required. Press Enter to restart..."
    Read-Host
    Restart-Computer
}

# Download and install Linux kernel update
$kernelUpdateUrl = "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi"
$kernelUpdatePath = "$env:USERPROFILE\Downloads\wsl_update_x64.msi"

Write-Output "Downloading Linux kernel update..."
Invoke-WebRequest -Uri $kernelUpdateUrl -OutFile $kernelUpdatePath

Write-Output "Installing Linux kernel update..."
Start-Process msiexec.exe -ArgumentList "/i", $kernelUpdatePath, "/quiet", "/norestart" -Wait

# Set WSL 2 as default
wsl --set-default-version 2

# Install Ubuntu via winget
Write-Output "Installing Ubuntu..."
winget install -e --id Canonical.Ubuntu

Write-Output "Setup complete! WSL 2 and Ubuntu are ready to use."

How to Run the Script:

  1. Save the script as SetupWSL.ps1.

  2. Open PowerShell as an administrator and enable script execution (if not already done):

    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
    
  3. Run the script:

    .\SetupWSL.ps1
    

This script automates the entire setup, installing WSL 2, the Linux kernel update, and Ubuntu, saving hours of manual configuration.


Why Work with 1it.pro?

At 1it.pro, we specialize in empowering small and medium-sized businesses with modern IT solutions. Our services include:

  • IT Infrastructure: Designing and implementing robust, scalable systems.
  • Automation: Streamlining repetitive processes with tools like n8n, Zapier, and Make for CRM integrations, messenger bots, email campaigns, and analytics.
  • Cloud Solutions: Seamless cloud migration and management for cost-effective operations.
  • Marketing & SEO: Boosting visibility with SEO, content marketing, and digital strategies.
  • AI Integration: Implementing AI to drive smarter, data-driven decisions.

Ready to streamline your development, cut costs, and scale your business?
Visit 1it.pro or contact us at contact@1it.pro to get a personalized automation and DevOps plan tailored to your business goals. Let’s build a faster, smarter future together!

🚀 Explore more guides on our blog 👉 blog.1it.pro
📧 Contact us: admin@1it.pro for expert IT guidance.
🌐 Explore more: Visit 1it.pro for top-tier IT solutions.

UA EN RU

Зв'язатися з нами

Telegram Email