Tux joins forces with Bill Gates!

Setting up Windows Subsystem for Linux (without Microsoft Store)

Kevin Feng
Nerd For Tech

--

Ah yes, Windows Subsystem for Linux (WSL)— that one “operating system” that’s overshadowed by Windows, Linux, and macOS (in that order, of course):

Stack Overflow Developer Survey 2022 results

At least WSL isn’t as unpopular as the enigmatic BSD OS…

But calling WSL an “operating system” might not be so apropos. Instead, it’s really a Windows feature that enables users to run a Linux environment without requiring a full virtual machine. Released in 2016, WSL has two versions: WSL 1 and WSL 2, the latter of which is more powerful, but also requires… (wait for it)

THE DREADED HYPERVISOR. For many people, enabling Hyper-V on their Windows machine is undesirable. Here are just a few reasons why you might not want to enable Hyper-V on your Windows computer:

  1. First and foremost, Hyper-V will conflict with other hypervisors, like VMWare Workstation, or VirtualBox. With Hyper-V enabled, you may be unable to access your virtual machines, and even if you are, Hyper-V could lead to performance issues within those machines.
  2. Since using Hyper-V introduces a thin layer of virtualization and keeps the resources used separate from the host, there will always be some degree of performance impact — running directly off of the host’s hardware is faster.
  3. Even if you are able to use other forms of virtualization, you might not be able to access all the hardware you want. If you’re using a virtual machine in VirtualBox and can’t access USB devices, then Hyper-V could be the root of that problem.

So now that I’ve established why enabling Hyper-V might be a problem, why does it matter? How different is WSL 1 from WSL 2? Well, they’re pretty similar, but there are some key differences. Although WSL 1 has good compatibility with most Linux applications, it uses a translation layer to convert Linux system calls into Windows ones. As such, running Docker directly in WSL 1 is not possible.

Docker whale is confused

However, with WSL 2, which utilizes a full Linux kernel alongside the Windows kernel, you can run Docker natively, which is a very powerful tool for standardizing software so that there’s no more talk of, “It runs on my machine.”

That being said, I already run Ubuntu 22.04 through a virtual machine on VMWare Workstation, and I’d rather have a fully-fledged VM be capable of running Docker than a subsystem terminal. For the time being, I’ll stick with WSL 1.

I am just your average Ubuntu enjoyer

Speaking of which, WSL 1 is what we’ll be installing today, and since it’s one of the most popular Linux distros, Ubuntu will be our flavor of Linux. On top of that, we’ll be doing everything without the usage of the Microsoft Store. Traditionally, you would install WSL by simply clicking “install” on its page within the Microsoft Store, but that’s not what we’re going to be doing.

Why? Well, my desktop doesn’t have access to it… And besides, not everyone has access to the Microsoft Store either. It’s actually quite a common problem for Microsoft Store to not install apps or not open at all.

Following the Microsoft installation instructions until we crash and burn

First, let’s navigate to the official Microsoft installation instructions for installing WSL:

We first open a terminal (either Command Prompt or PowerShell) in adminstrator mode and run this command:

wsl --install

We should then restart our computer for the changes to take effect. Once our computer reboots, let’s try to install Ubuntu with WSL:

wsl --install -d Ubuntu

And we get…

An error. Looks like we already crashed and burned. Or maybe you didn’t get an error and instead, see a screen like this:

If that’s the case, you’re almost done! Just enter a username and password (don’t forget it) and you’re in. But for the less fortunate people who attract bugs almost as much as light mode, here’s what to do if you’re unable to install a Linux distro with wsl --install.

Ensuring Hyper-V is off and that we’re using WSL 1

Before we even try to install Ubuntu using an alternative method, we should ensure that Hyper-V is off and that WSL 1 is the default version of WSL. To complete the latter task, we can simply run the following:

wsl --set-default-version 1

To ensure that Hyper-V is not enabled, we’ll have to do a couple of things. First, we should check that it’s disabled through Windows Programs and Features:

  1. Open Control Panel
  2. Select Programs and Features
  3. On the left sidebar, select “Turn Windows features on or off’
  4. Uncheck Hyper-V if it isn’t already

Don’t restart your computer just yet. We’re going to change one more setting to really make sure that Hyper-V is disabled. Open an instance of Command Prompt or PowerShell in administrator mode and execute this command to make sure that the hypervisor doesn’t launch:

bcdedit /set hypervisorlaunchtype off

You should see this output:

Now you can restart your computer, and Hyper-V should no longer be a problem.

Installing Ubuntu

Since we couldn’t install Ubuntu with the provided command from the Microsoft documentation, we’ll install it using an AppxBundle, which is just a file type that bundles software for Windows 10 apps.

From this blog post, scroll down to the “Download and installation” section:

You’ll find a direct link to install Ubuntu. This will download the AppxBundle file, which we’ll need to extract using some type of compression tool. Although my go-to is WinRAR, I found that 7-Zip was much easier to use. You can install it very easily from this page.

Once the AppxBundle file has finished downloading (it can take quite some since it’s almost 1 GB), you’ll want to extract it to a single folder using 7-Zip (right-click on it and mouse over the 7-Zip menu) Inside that folder, you’ll see some Appx files, which you can run by double-clicking on:

Run the Appx file and you should see a screen to install Ubuntu (in my case, Ubuntu is already installed):

Simply click “Launch” and you’re good to go if you get to the “Installation successful!” screen mentioned earlier:

However, if you run into an error code of 0x80070422 indicating that WSL won’t start, try running this command with an elevated terminal:

powershell restart-service vmms

Ideally this should solve the 0x80070422 error (it worked for me), but if it doesn’t you can also try running this command:

sc config LxssManager start=auto

Hopefully with those commands WSL will work, so try installing Ubuntu again by running the Appx file. If it works, you can set a UNIX username and password and you’re all set! The next time you want to get into your Linux environment via the terminal, simply type wsl and you’re in. Type exit to perform the reverse.

Look at this glorious Bash shell inside of Windows Terminal

Conclusion

WSL is a versatile and powerful tool for many developers, given the fact that Windows is still the most popular operating system. It offers a solution for Windows users to access a Linux environment without setting up a fully-fledged virtual machine. It shouldn’t be forgotten that Hyper-V can lead to some conflicting problems with other VMs, so deciding between WSL 1 and WSL 2 is up to the individual.

Now excuse me while I go configure Neovim for the 69th time this year.

--

--