How to Install Node.js and NPM on WSL — Step-by-Step Guide

If you are coding on Windows and not using WSL (Windows Subsystem for Linux), you may be making your development workflow harder than necessary.

This guide explains how to install Node.js and NPM on WSL using the same type of setup many professional developers use.

Why Use WSL for Node.js Development?

Running Node.js natively on Windows can sometimes cause issues with:

  • File paths
  • File watching
  • Permissions
  • Development tools and compatibility

WSL provides a real Linux environment on Windows, giving you better compatibility with many tutorials and open-source tools.

Before starting, make sure WSL is installed on your Windows system.

Step 1: Open Your WSL Terminal

First, open your WSL terminal.

You can search for Ubuntu from the Windows Start menu or open Windows Terminal and start your WSL environment.

Step 2: Update Your Package List

Before installing anything, update your package list.

Run:

sudo apt update

Then upgrade the available packages:

sudo apt upgrade

This makes sure your WSL environment is up to date before installing Node.js.

Step 3: Install Node.js Using NVM

Now it’s time to install Node.js.

It is better not to install Node.js directly from the Ubuntu repository because the available version may be outdated.

Instead, use NVM (Node Version Manager).

NVM allows you to install and switch between different Node.js versions easily.

Install NVM by running the NVM installation command in your WSL terminal.

After the installation finishes, close and reopen your terminal.

Then activate NVM.

Once NVM is ready, install the latest LTS version of Node.js with:

nvm install --lts

Step 4: Verify Node.js and NPM

Now confirm that Node.js and NPM were installed correctly.

Check the Node.js version:

node -v

Then check the NPM version:

npm -v

If both commands return version numbers, Node.js and NPM are installed successfully.

NPM is automatically included with Node.js, so you don’t need to install it separately.

Step 5: Test Node.js with a Quick Project

Let’s test the installation with a simple Node.js project.

First, create a project folder:

mkdir my-app

Then enter the folder:

cd my-app

Initialize NPM:

npm init -y

Create a JavaScript file and add a simple console.log() statement.

For example:

console.log("Node.js is working!");

Run the JavaScript file with Node.js.

If the message appears in your terminal, Node.js is working correctly.

Use WSL with VS Code

If you use Visual Studio Code with the WSL extension, you can open your WSL project folder directly in VS Code.

This gives you the best of both worlds:

  • Windows interface
  • Linux development environment
  • Linux performance and compatibility

Recap

The complete setup is:

  1. Open your WSL terminal.
  2. Update your system with sudo apt update and sudo apt upgrade.
  3. Install NVM.
  4. Install the latest LTS version of Node.js.
  5. Verify Node.js and NPM with node -v and npm -v.
  6. Create and test a quick Node.js project.
  7. Use VS Code with WSL for your development workflow.

That’s the complete setup for installing Node.js and NPM on WSL and getting started with Node.js development on Windows.
watch full video on youtube

Leave a Reply

Your email address will not be published. Required fields are marked *