Setting up Nodejs with nvm on WSL 2

cryptus_neoxys

Dev Sharma

Posted on November 15, 2021

Setting up Nodejs with nvm on WSL 2

Installing node.js in WSL 2

( NOTE : Although this tutorial demonstrates WSL 2/Ubuntu, this installation is primarily for Linux) In this tutorial, we will use node version manager or nvm to install and manage node versions. nvm certainly has its advantages as it allows you to easily install and manage multiple node versions on your system. This also means you can easily switch node and npm versions with a single command and that comes in handy.

If you don't already have it, install curl



sudo apt-get install curl


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



Enter fullscreen mode Exit fullscreen mode

( Note: instead of v0.38.0 Use the latest version of nvm from GitHub)

Verify your installation using



command -v nvm



Enter fullscreen mode Exit fullscreen mode

(If you get an error command not found, restart your shell and try again.)

Let's install the LTS and latest stable version of Nodejs, you can also choose one of those if you prefer, but believe me, it's super simple to switch between different node versions using nvm.

Install the LTS version



nvm install --lts



Enter fullscreen mode Exit fullscreen mode

Install the latest version



nvm install node



Enter fullscreen mode Exit fullscreen mode

You can check all the installed versions using the following command



nvm ls



Enter fullscreen mode Exit fullscreen mode

image.png

Check the version of node and npm you are running:



node --version
npm --version



Enter fullscreen mode Exit fullscreen mode

image.png

You can install a specific version of node:



nvm install 14.17.0



Enter fullscreen mode Exit fullscreen mode

To use a specific node version:



nvm use 14.17.0
# lts version
nvm use --lts
# latest stable version
nvm use node



Enter fullscreen mode Exit fullscreen mode

Feel free to reach out to me on Twitter @cryptus_neoxys and connect with me on LinkedIn.


Refs & Resources

Microsoft Docs

nvm-sh/nvm

💖 💪 🙅 🚩
cryptus_neoxys
Dev Sharma

Posted on November 15, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Setting up Nodejs with nvm on WSL 2
linux Setting up Nodejs with nvm on WSL 2

November 15, 2021