Skip to content

How to quickly setup NodeJS

Posted on:May 12, 2024 at 11:44 PM

2 min read

If you’d like to see the video version Click here.

I had to re-install my WSL2 Ubuntu distro for Web Development, so I decided to document how I setup things starting from NodeJS. These steps are meant to be executed on a Debian based Linux distribution, but they are valid also for Mac OSX.

NodeJS

I often switch from one project to another and each project requires a different version of NodeJS. I am too lazy to manually install and change my PATH variables to perform the switch so I always install NodeJS through nvm.

What is NVM?

NVM is a Node Version Manager, a CLI tool for NodeJS that provides utilities to install and switch from one version of Node to another in a matter of seconds.

Install NVM

Open a new terminal and paste this command:

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

Please note: If this post is too old, please make sure to replace v0.39.7 with the latest version of nvm.

Install NodeJS via NVM

Open a new terminal and paste this command:

nvm ls-remote

from the list that will appear, select the version you’d like to install. If you are not sure, install the latest Long Term Support (LTS) version with this command:

nvm install --lts

Add .nvmrc to your project

One of the best features of nvm is the .nvmrc. It is a file that you can add inside the root directory of your NodeJS project to allow nvm users to install and use the correct NodeJS version without having to think about it. It is very good for CI/CD too!

To create a .nvmrc, open a new terminal on the root directory of your project and paste this command:

node -v > .nvmrc

To test if it works, paste this command:

nvm install && nvm use

You may create a bash script inside your .bashrc that automatically looks for an .nvmrc file in your directory and performs the install and use for you. Click here to learn how.

Conclusions

This was a very quick introduction to how I setup NodeJS on my environment using nvm. If you have any questions please refer to the official documentation or contact me via my Social Links.