Installing Node.js on a Linux machine can be a bit tricky, especially if you’re not familiar with the command line. One of the best ways to do this is by using a tool called NVM (Node Version Manager). NVM makes it easy to install, manage, and switch between different versions of Node.js on your Linux machine. In this blog post, we’ll show you how to use NVM to install Node.js on your Linux machine.

For video version of this blog please check out my video on https://www.youtube.com/watch?v=FaGtH5CDFCk

TL;DR

node_js_nvm_linux

Step 1: Update Your Linux Machine

First, you need to make sure that your Linux machine is up to date. To do this, open a terminal window and run the following command:

sudo apt-get update

This command will update your Linux machine’s package manager with the latest package information.

Step 2: Install Curl

Next, you need to install curl. Curl is a command-line tool that allows you to transfer data from or to a server using various protocols. To install curl, run the following command:


sudo apt-get install curl

Step 3: Install NVM

Once curl is installed, you can use it to install NVM. To do this, run the following command:


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

This command will download and install NVM on your Linux machine.

Step 4: Activate NVM

After NVM is installed, you need to activate it by running the following command:


source ~/.nvm/nvm.sh

This command will add the NVM command to your terminal’s command path.

Step 5: Install Node.js

Now that NVM is installed and activated, you can use it to install Node.js. To do this, run the following command:


nvm install node

This command will install the latest version of Node.js on your Linux machine. You can check the version of Node.js you have installed by running the following command:


node -v

You can also install specific version of Node.js using nvm install command followed by version number like nvm install 12.18.4

Step 6: Switch Between Node.js Versions

Once you have Node.js installed, you can use NVM to switch between different versions of Node.js. To see a list of all the versions of Node.js you have installed, run the following command:


nvm list

To switch to a specific version of Node.js, use the following command:


nvm use [node version]

Replace [node version] with the version of Node.js you want to use.

That’s it! You now know how to use NVM to install and manage multiple versions of Node.js on your Linux machine. NVM makes it easy to switch between different versions of Node.js, which is especially useful if you’re working on multiple projects that require different versions of Node.js.

Happy learning/coding 😎