A Beginner’s Guide to Installing WSL, Docker, and Running Ubuntu on Windows and macOS

What is WSL?
The Windows Subsystem for Linux (WSL) is a feature by Microsoft that lets users run a Linux environment directly on Windows without needing a virtual machine or dual boot. It enables developers, IT professionals, and tech enthusiasts to use Linux commands, tools, and applications alongside Windows programs seamlessly.
WSL 2, the latest version, uses a real Linux kernel, offering improved performance and compatibility. It supports popular distributions like Ubuntu, Debian, and Kali Linux, which can be installed via the Microsoft Store. WSL allows developers to test, build, and deploy applications in a Linux-like environment while using Windows, making it ideal for cross-platform development.
With its lightweight design, WSL integrates smoothly with Windows, allowing access to Linux files via Explorer and running Linux commands in PowerShell or CMD. It’s a game-changer for developers, system administrators, and cybersecurity professionals, providing the best of Linux and Windows in one platform.
How to Install WSL on Windows and macOS
Installing WSL on Windows
Requirements:
Windows 10 (version 2004 or later) or Windows 11.
Ensure Virtualization is enabled in the BIOS.
Note: Windows 10 may have bugs, so avoid it if your machine shows any errors. Alternatively, you can install it on a virtual machine using Windows 11 or directly install Linux.
Open Windows Features using the Start menu:
Click on the Start menu or press the Windows key.
Type “Windows Features” in the search bar.
Select “Turn Windows features on or off” from the search results.
Enable “Windows Subsystem for Linux”.
Click Ok.

Steps
Enable WSL:
Open Command Prompt or PowerShell as Administrator.
Run the following command to install WSL:
wsl --installThis command installs WSL 2, the default Linux distribution (usually Ubuntu), and ensures everything is configured.
wsl.exe --install -d Ubuntu
Note: Setup your username & password.

Restart Your PC:
After running the command, restart your computer to apply changes.
Note: If your system asks for a restart, please go ahead and restart it.

Installing WSL on macOS
While WSL is not natively supported on macOS, there are alternative methods to run Linux environments:
Option 1: Using Docker Desktop with Linux Containers
Install Docker Desktop:
Download Docker Desktop for macOS from the official website: Docker Desktop for Mac.
Follow the installation instructions.
Enable Linux Containers: Docker on macOS uses Linux containers, and you can set up a Linux-based development environment inside Docker.
Option 2: Using Virtual Machine Software (e.g., Parallels, VMWare)
Install Virtual Machine Software:
Download Parallels Desktop or VMWare Fusion for macOS.
Create a new virtual machine with a Linux distribution like Ubuntu or Debian.
Set Up the Virtual Machine: Follow the instructions to install the Linux distribution, then access the Linux environment on your macOS device.
What is Docker?
Docker is a tool that helps developers package applications and all their dependencies into a container, which is a lightweight, portable, and self-sufficient unit. This makes it easy to run applications consistently across different environments—whether on your laptop, a server, or the cloud—without worrying about compatibility issues.
For example, imagine you are developing a web app using Node.js. With Docker, you can create a container that includes your Node.js app, all the libraries, and configurations it needs. Now, whether you run the app on your machine or on a different computer, Docker ensures it behaves the same way, avoiding the "it works on my machine" problem.
Unlike virtual machines, Docker containers share the same operating system but remain isolated. This makes them faster and more efficient, allowing you to run many containers on a single system.
Docker also makes it easier to scale and manage applications. For instance, if your web app becomes popular, you can quickly add more containers to handle the increased traffic, all without disrupting the rest of the app.
How to Install Docker on Your Machine
Installing Docker on Windows
Requirements:
Windows 10 (64-bit) or Windows 11, with version 1903 or higher.
Enable Virtualization in BIOS (If you encounter any errors, you may need to enable this option. However, it's unlikely that you will experience any errors.).
Steps
- Download Docker Desktop:
Visit the official Docker website and download Docker Desktop for Windows.
Do not install the ARM version for Windows because it has some bugs.
Install Docker Desktop:
Run the installer file and follow the on-screen instructions.
Ensure that WSL 2 is enabled during installation for better performance (optional).
Start Docker Desktop:
After installation, open Docker Desktop from the Start menu.
Installing Docker on macOS
Requirements:
macOS 10.15 (Catalina) or newer.
An Apple Silicon or Intel chip.
Steps
Download Docker Desktop:
Go to the Docker Desktop download page and download the version for macOS.Install Docker Desktop:
Open the downloaded
.dmgfile and drag the Docker icon to the Applications folder.Launch Docker Desktop from Applications.
Installing Docker on Linux
Requirements:
- A 64-bit Linux distribution like Ubuntu, Debian, or Fedora.
Steps
Update System Packages:
sudo apt update && sudo apt upgrade -yInstall Docker:
For Ubuntu:
sudo apt install docker.ioFor other distributions, refer to Docker's official documentation.
Start Docker Service:
sudo systemctl start docker sudo systemctl enable dockerVerify Installation:
docker --version
Testing Docker Installation
To confirm that Docker is running correctly:
Open a terminal or command prompt.
Run:
docker run hello-worldThis downloads and runs a test container, printing a "Hello from Docker!" message.
How to Set Up Docker with WSL
Running Docker with Windows Subsystem for Linux (WSL) provides a seamless development environment that integrates Linux commands with Docker's powerful container management. Below is a step-by-step guide to set it up.
Step 1: Ensure Docker Is Installed
Step 2: Pull the Ubuntu Image
Open your terminal or command prompt.
Run the following command:
docker pull ubuntuWhat happens?
Docker connects to Docker Hub, the default image repository.
It fetches the latest version of the official Ubuntu image unless a specific version is specified.
Step 3: Run a Container with Ubuntu
Start a new container using the Ubuntu image:
docker run -it ubuntuWhat happens?
Docker creates a container from the Ubuntu image.
The
-itflags allow interactive mode and allocate a terminal for the container.You are now inside the container, running Ubuntu.
Run commands inside the container:
apt update apt install curlThese commands function as if you were on a native Ubuntu system.
Conclusion
In this guide, we've walked you through the entire process of setting up WSL (Windows Subsystem for Linux), installing Docker, and running Ubuntu containers on both Windows and macOS. Whether you're a developer looking to streamline your environment or someone eager to try out Docker and Ubuntu, this process opens up a world of possibilities for containerized applications.
Docker and WSL are powerful tools that make development smoother, and setting them up is an essential skill for anyone diving into modern development practices.
If you have any questions or need further clarification, feel free to drop a comment below! This section is open for discussions, and I'd be happy to help.
Thank you for reading, and happy coding! 🚀