This page looks best with JavaScript enabled

The Right WSL Setup for using Node

 ·   ·  ☕ 3 min read

A few node packages have been causing me pain lately. Who knew that my Windows 10 addiction can get me into trouble with node?

There are, of course, multiple ways to solve the node problem on Windows.

  1. Do not use the offending package :).
    If there is no support for Windows, your great program does not get written using the specific package. Hell, yeah.

  2. Use NVM to juggle between node versions and check whether the problem goes away.
    I did something similar when using strapi-js. I could not get it to work on Node 10 or 11.

  3. Try using Git Bash or something similar.

  4. Or, hop on to the train to Linux - Windows Subsystem for Linux to be specific

I live life on the edge - so, Linux.

Enable WSL & Install Linux within Windows

First, go ahead and enable WSL.

  1. Go to Control Panel\Programs\Programs and Features
  2. Select “Turn Windows features on or off” on the left navigation link
  3. Check “Windows Subsystem for Linux” to install

Next, you have to choose a Linux distribution to install. You can do that quite easily by going to Start Menu > Microsoft Store > Search for “Linux”.

Select a Linux distribution and click ‘Get’ to install.

Alas, it was not that simple for me. Windows Store was stuck in a loop and refused to install any app. Multiple rounds of reset, clearing cache etc did not help. Therefore I did the next best thing - left that problem for another day, and followed an alternative.

  1. Download the Debian distribution for WSL from Microsoft Site.
  2. Click on the file to run the Debian installation. Provide a user id/password for Linux when prompted

Configure Linux in Windows

Once the Linux installation is complete, it is time to configure the app.

The Shell

Click on Start > Debian GNU/Linux to start the Debian shell. You can use the default command shell by playing around with the command prompt options.

console-bash-wsl.jpg

Alternatively, use the following line to start bash in Cmder (or in your favorite emulator).

%windir%\system32\bash.exe ~ -cur_console:p

cmder-wsl-debian.jpg

Update Packages

In the bash prompt, update package versions.

sudo apt update

You will have a problem in using wget and other such utilities with https protocol. An example of error below.

ERROR: The certificate of ‘curl.haxx.se’ is not trusted.

Run the below command to install trusted certificate providers.

sudo apt-get install ca-certificates

Install curl

You can find the latest version of curl by going to [https://curl.haxx.se/download/] and use wget to get latest version and build locally. I am lazy and used apt to get an older version.

sudo apt install curl

Install node

Get latest node.

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

And, install node.

sudo apt install nodejs

Finis

Code away to Javascript glory.

Stay in touch!
Share on

Prashanth Krishnamurthy
WRITTEN BY
Prashanth Krishnamurthy
Technologist | Creator of Things