How to Install Node.js and npm on WSL2

We have a fresh installation of WSL2, and now we want to install node and npm.

Once we’ve opened up our Ubuntu terminal, we can run a few commands.

1. Install cURL

sudo apt-get install curl

2. Install nvm

curl -o- | bash

Be sure to change the v0.38.0 in the path to the most recent version available. If we install a newer version of nvm, it’ll replace the older one.

Now, restart the terminal.

3. Verify installation

command -v nvm

It should return nvm.

4. Install Node.js (two options)

nvm install --lts # Latest stable LTS release (recommended)
nvm install node # Current release

5. Verify installation

node --version # node.js
npm --version # npm