NOTE: This post will be updated as time goes on with further tips, and if the installation process changes in any way.
If you're anything like me, then you're a developer with a love for (or at the very least a respect for) all different kinds of modern operating systems. They all provide their own unique user experiences, and all have something to offer for different people.
However, if you're also like me, you may have finished up a programming bootcamp where it was made clear that MacOS is the preferred OS environment for web development, and that using Windows would lead to a world of headaches and compatibility issues.
While I love both MacOS and Windows equally for different reasons, I understood why:
- MacOS has the benefit of a built in terminal to interact with its file system.
- MacOS is built on a Unix kernel, upon which most frameworks and languages built for web development work seamlessly.
- MacOS has Homebrew, a package manager that uses terminal commands to install and use open-source software.
Windows does not function on a Unix kernel, and has its own completely different set of file structures and developer tools. This isn't inherently bad, and is quite good for some other programming endeavors, but is less effective for modern web development that makes consistent use of packages and servers.
Enter Linux, and more specifically Windows Subsystem for Linux.
Linux is an open-source Unix operating system that comes in all sorts of different flavors and varieties known as distros, all of which have roughly the same core benefits for web development. They differ from MacOS in a large number of ways, but at their lowest levels offer comparable and equally efficient development experiences.
It used to be that, in order to get access to a Linux development environment on a Windows machine, you had to either install a full Linux distro alongside your Windows installation (known as dual-booting or multi-booting), or install Linux inside of a virtual machine or VM, essentially a sandboxed instance of that operating system running in a window within your main operating system.
However, in 2016 Microsoft introduced Windows Subsystem for Linux, a compatibility layer that allowed Linux executables and command line interfaces to be run within Windows 10. Then, in 2019, Microsoft introduced WSL 2, a full fledged Linux kernel operating in a lightweight and efficient virtual machine natively through Windows (and the version we'll be going over in this post.)
The benefits of using WSL are many, but the fundamental benefit is that you can now have an entire, native Unix development environment and filesystem built into your Windows installation, allowing quick and easy access to your development files and a full fledged terminal and command line, while also having your native Windows programs, games and functionality immediately available. Cool stuff, right?
Let's begin our installation by following the core steps listed on Microsoft's own website:
Open Powershell.exe as an administrator and run:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Make sure your Windows installation is at at least version 2004, Build 19041 or higher (which can be checked by pressing Windows logo key + R, type winver, then selecting OK.
Now, make sure that the optional "Virtual Machine Platform" is activated by going back into your Powershell.exe instance and typing:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Now restart your computer to complete the update to WSL 2!
Open Powershell.exe back up, and type:
wsl --set-default-version 2
You might get an error along the lines of
WSL 2 requires an update to its kernel component. For information please visit https://aka.ms/wsl2kernel
If so, visit the link provided in the error and install the provided kernel, then run the command again.
Now, open up the Microsoft Store app on your computer, and search your a Linux distribution.
In this situation I would advise installing Ubuntu, as it's one of the more user-friendly, stable and accessible versions of Linux available. Choose the version that just says Ubuntu without any version numbers, as this will automatically install the most up-to-date stable version of the OS.
Now, open up the newly installed Ubuntu app on your computer, and a new terminal should open. It will take some time to do an initial install, and then ask you to set up your username and password for the Linux install (note: this is different than your Windows username and password, although you can use the same ones here as well if you'd like.)
Take one more moment to type the following into your Linux terminal to upgrade your installation's packages to their latest versions:
sudo apt update && sudo apt upgrade
And congratulations, you're now officially set up with WSL 2 on your Windows 10 machine! Let's move on to some further tips and pieces of information that you should know when coming from MacOS. At this point you can essentially use the Linux terminal to continue your development
The virtual machine containing all of your newly created Linux files can be found either by typing the following into your Linux terminal to open up a Windows file explorer at that location:
Or by searching for the following in your Windows file explorer:
These files are connected to your Windows installation as a network drive and are fully accessible through Windows' interface, but are saved in a different file structure. I would recommend adding this folder to your Quick Access menu on the side of your file explorer for easy access.
Previously in WSL 1 it was faster to save your development files in your Windows filesystem, but with WSL 2 you will see an improvement in I/O performance by keeping all of your development files exclusively in this Linux directory.
The advantage of this is that you have a filesystem and installation entirely devoted to development, safely sandboxed off from the rest of your computer. If something goes wrong, or you need to delete it and reclaim hard drive space from projects and packages, it's an easy process.
Since WSL lacks a GUI (for now), you'll be doing most things on the command line. This is very good practice in the long run since being confident on the command line is one of the hallmarks of an experienced developer.
You can continue to use the installed Ubuntu (or other distro) app as your dedicated terminal, OR you may install the newly released and well regarded Windows Terminal from the Microsoft App Store.
The Windows Terminal is open-source and configurable, although understanding how to make changes to the settings can be a bit tricky as it requires editing a JSON file.
The most important basic change to make is setting the default shell that it opens into to your WSL installation. You can do this by opening the settings from the Terminal menu bar, then going through your list of "profiles" to find the one matching your Ubuntu/WSL install and copying the "guid" value:
Then pasting it into the "defaultProfile" value at the top of the file:
And you're done! There are plenty of other settings and themes to experiment with, and I recommend reading through some of the official documentation on the subject.
This is a question that comes down to preference, but there's one main option to pick that outweighs the others due to pure compatibility: Visual Studio Code
VSCode is an open source code editor from Microsoft, and features excellent WSL integration.
First off, install VSCode on your Windows machine as you would for any other application or program. Then, once you've installed and set it up initially, install the Remote - WSL extension.
This allows you to use VSCode's graphical interface as a regular Windows application, while it actually opens up and does all of its logic inside of your Linux installation. It should work smoothly for all of your Linux development files, and will allow you to utilize the integrated terminal in VSCode in addition to your Windows Terminal/Ubuntu apps.
You should also be able to type the following from a Linux directory to open it in VSCode:
That's it for right now, though I'll be returning to this blog post later on to add more tips and tricks for WSL users, especially those switching from MacOS. Thanks for reading!