Skip to content

Running Linux on Windows with WSL: A guide for developers and non-developers⚓︎

If you've ever wanted to use Linux commands within your Windows environment, the Windows Subsystem for Linux (WSL) is an excellent tool by Microsoft. It allows you to run Linux distributions on Windows, primarily through the command line, but also supports some graphical applications.

As a Linux user, my search for this WSL solution began after a frustrating experience with Windows tools like Git Bash, which felt clunky and limited in comparison.

As you'll see, installing WSL alongside with Oh My Zsh terminal, transforms the Windows terminal into a far more powerful and visually appealing environment, similar to what I was used to on Linux.

For non-technical users, WSL offers a gentle introduction to Linux, letting you explore this powerful operating system without fully switching away from Windows. With WSL, you can try out new tools and commands that can simplify tasks and boost productivity, especially useful if you're curious about Linux or have heard about its efficiency for certain tasks.

The setup I present here, allows you to gradually get comfortable with a Linux environment, learn at your own pace, and see the benefits firsthand, all within the familiarity of your Windows system.

I’m confident that once you experience the flexibility and ease of using Linux tools within Windows through WSL, you might just find yourself wondering how you ever worked without it!

What is WSL?⚓︎

First things first. What is WSL? It's a tool that enables Linux to run directly within Windows, which is helpful for software development, system administration, or just exploring Linux tools without leaving Windows. Originally introduced as WSL1, WSL2 is an improved version that offers more robust performance and a real Linux kernel for enhanced compatibility.

Key benefits of WSL⚓︎

  1. Low resource usage: Unlike full virtualization software like VirtualBox or VMware, WSL uses fewer resources, making it ideal for quickly accessing Linux tools without heavy memory or CPU demands.

  2. Developer-focused but broadly useful: While it’s popular with developers, WSL offers useful tools for non-programmers as well, making it a versatile solution for anyone who wants to use Linux utilities within Windows.

  3. Integration with Windows: You can access Windows file systems directly from within Linux and vice versa, creating a seamless experience for file management across both environments.

WSL usage prerequisites:⚓︎

To install the Windows Subsystem for Linux (WSL), your machine needs to meet the following prerequisites:

  1. Operating System:

    • Windows 10 (Version 2004 and higher, with Build 19041 and higher).
    • Windows 11 (any version).
    Tip

    To check your Windows version and build number press Win + R to open the Run dialog, type winver, and press Enter.

  2. System Requirements:

    • 64-bit Processor: WSL2 requires a 64-bit processor. Older 32-bit versions of Windows cannot run WSL2.
    • Virtualization Support: Your system must support virtualization. This is typically available on most modern CPUs, but make sure it’s enabled in the BIOS/UEFI 'settings.
    Tip

    Ensure that virtualization is enabled in your BIOS or UEFI settings. This is often labeled as Intel VT-x (for Intel processors) or AMD-V (for AMD processors).

  3. Windows Update: Make sure your system is up-to-date with the latest Windows updates. WSL2 requires specific updates that are available in the latest versions of Windows 10 and 11.

Once you have verified these prerequisites, you can proceed with the installation.

Windows 11 WSL installation⚓︎

To enable WSL on Windows 11:

Info

If you're using Windows 10, the installation process is a bit different. A quick online search should guide you through it, but if you need any extra help, feel free to ask in the comments below.

  1. Open PowerShell as Administrator.
  2. Run the following command:

    wsl --install # (1)!
    
    1. 🙋‍♂️ This command installs WSL, sets WSL2 as the default version, and installs Ubuntu as the default Linux distribution. After the installation, you may need to restart your computer. To install other Linux distributions, use the command wsl --install -d <distribution-name>. You can view available distribution options by running wsl --list --online. For a full list of wsl command options, use the --help flag. For example, you can check the status and list all installed WSL distributions by using wsl --list --verbose.
    Tip

    Install Windows Terminal through Microsoft Store to streamline your WSL experience.

  3. After installation, you can launch WSL by searching for "WSL" or "Ubuntu" in the Start Menu .

  4. When you open WSL for the first time, you'll be prompted to create a Linux username and password for administrative tasks.

    Tip

    ⚠ When you're prompted to enter your password, you won’t see any characters appear on the screen as you type. Don't worry, this is normal and a security feature. Just type your password carefully and press Enter.

Accessing files and running linux applications⚓︎

One unique feature of WSL is the ability to interact with files across both Windows and Linux environments.

For instance:

  • Windows directories are accessible from Linux via /mnt/c.
  • You can open Linux files directly in Windows Explorer by typing \\wsl$\Ubuntu (1) in the address bar.

    1. 🙋🏿‍♂️ Replace Ubuntu in case your linux distribution is different.

Example: running a simple web server⚓︎

A quick example of how WSL can be used effectively is running a web server:

  1. In WSL, navigate to the directory where you want to serve files.
  2. Run a simple Python HTTP server:

    python3 -m http.server 8000
    
  3. Access this server in a Windows browser by going to http://localhost:8000.

Using a Fancier Terminal⚓︎

To enhance our user experience, let's chance the Ubuntu's default terminal to Oh My Zsh. Installing Zsh with Oh My Zsh on WSL create a powerful and visually appealing environment that closely mirrors the efficiency of Linux.

It introduces features like auto-suggestions, syntax highlighting, and easy customization, making command-line tasks smoother and more intuitive.

This strategy not only enhances the terminal’s appearance but also delivers a truly efficient, Linux-like command-line experience for Windows users.

  1. Open your WSL terminal and run the commands below to install Zsh:

    sudo apt update # (1)!
    sudo apt install zsh -y
    chsh -s $(which zsh) # (2)!
    
    1. 🙋‍♂️ Run one command at the time.
    2. 🙋‍♂️ You may need to log out and log back in to see the change, or simply open a new WSL terminal window to start using Zsh.
  2. Install Oh My Zsh:

Oh My Zsh is a framework for managing Zsh configurations, and it comes with themes and plugins that make your terminal experience more powerful and customizable.

We'll cover just the basics here, but it’s exactly what we need to get started.To install it, use this command:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Give Zsh and Oh My Zsh a try on WSL, and let me know in the comments below if you enjoy the more visually appealing and productive terminal experience!

Final Thoughts⚓︎

WSL bridges the gap between Windows and Linux, creating a streamlined workflow for development and general Linux usage within Windows. This integration not only serves technical needs but is also an excellent entry point for those new to Linux.

For newcomers, WSL offers a way to explore Linux tools and get accustomed to the Linux terminal without committing to a full operating system switch. This means you can experiment without reconfiguring your entire setup, making it easy to see if Linux aligns with your expectation and workflows.

For technical users, WSL resolves some familiar frustrations, like line-ending compatibility issues between Windows and Linux. By writing and running code in a Linux environment, you avoid these interruptions, improving the consistency of your development process.

Additionally, WSL provides a more robust terminal experience than options like Git Bash, CMD, or PowerShell, which often fall short in user experience, at least in my opinion. With WSL, you gain access to a more native Linux terminal, offering improved tool support and a smoother, more powerful command-line interface.

Whether you're a developer or just curious, WSL presents a flexible, efficient gateway to Linux that can significantly enhance your productivity and comfort in either system.

Get in touch

I worked hard to ensure that all the content in this post is accurate and error-free. However, I know that mistakes can happen, as I'm only human! If you find any, or if you have questions or suggestions, please don’t hesitate to reach out in the comment section below.

If you prefer, send an email to gabrielbdornas@gmail.com.

References⚓︎

Comments