DEV Community

Cover image for WSL2 for web development
Matteo Galdi
Matteo Galdi

Posted on

WSL2 for web development

With the release of build 18361, Windows 10 introduces a new version of his Windows Subsystem Linux. It's amazing. It works very well for me, and that's how I have done.

I wouldn't say I like Windows as a development environment. I love Linux, and I love to use the terminal. I've to say that I'm not bound to any particular kernel version or Linux distro. I like fundamental Linux utilities that speed up my routine.

Prerequisites

  • Windows 10 build 18361

Part One: How to install

Open PowerShell as admin and type as follow.

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

If you restart your computer, you can install a Linux distro downloading it on the Microsoft Store, but you will use the first version of WSL. Follow me to update.

WSL 2 has a lot of improvements compared to its predecessor, to update type as follows.

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Now you have to set WSL 2 as the default version (it will be in the upcoming Windows versions).

wsl --set-default-version 2

99% you get this error 0x1bc because WSL 2 runs a real Linux kernel and you don't have one, you can install it from here.

Now repeat the above command to set the default version to WSL2 finally. Restart your computer.
Now you can install a Linux distro of your choice (here all those available). I chose Ubuntu 20.04 because it has all the tools I need out of the box.
Launch the Linux app you've just installed, follow the on-screen instructions, and enjoy your Linux distro running inside Windows.

Part two: Node setup

To set up the Node environment, I highly recommend using nvm for two main reasons:

  1. You can easily switch between Node versions
  2. nvm installs Node in your home folder. It would be best if you never used npm with "sudo" (useful resources here)

To install nvm, open your WSL, move to your home directory typing cd and type:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

Now relaunch your terminal.

Type nvm for a list of all available commands.

To install the LTS version of Node (and NPM) type as follow.

nvm install lts

That's it. Now you can use Node and NPM.

npm i -g //installs packages globally without sudo

Latest comments (0)