Effortlessly Install Node.js and npm on WSL2

Hey there, if you using Windows Subsystem for Linux (WSL2) and looking to set up Node.js and npm? Here's a simple guide to help you get started:

First things first, let's ensure that we have cURL installed on our system. Run the following command in your Ubuntu terminal:

sudo apt-get install curl

Now, let's install nvm (Node Version Manager) using the following command:

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

Do keep in mind to replace the v0.38.0 in the path with the latest version available. Updating to a newer version of nvm will automatically replace the older one.

Once that's done, let's restart the terminal to apply the changes.

To verify the installation, run the following command:

command -v nvm

If all goes well, you should see nvm as the output.

Now, it's time to install Node.js. You have two options to choose from:

  • To install the latest stable Long-Term Support (LTS) release, run:
nvm install --lts
  • To install the current release, run:
nvm install node

Finally, let's verify the installation by running the following commands:

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

And that's it! You should now have Node.js and npm installed on your WSL2 system. Feel free to comment with any queries.