Setting up Nodejs with nvm on WSL 2
2 min read
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
sudo apt-get install curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
(Note: instead of
v0.38.0 Use the latest version of nvm from GitHub)
Verify your installation using
command -v nvm
(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
Install the latest version
nvm install node
You can check all the installed versions using the following command
Check the version of node and npm you are running:
node --version npm --version
You can install a specific version of node:
nvm install 14.17.0
To use a specific node version:
nvm use 14.17.0 # lts version nvm use --lts # latest stable version nvm use node
Feel free to reach out to me on Twitter @cryptus_neoxys and connect with me on LinkedIn.
Refs & Resources
If you loved the article and would like to support me, you can buy me a coffee.