How to Install Node JS on Linux, Mac, and Windows

Prerequisites: Linux Installation: Step 1: Open Terminal Step 2: Installing nvm: Step 3: Check nvm Installation: To view available Node.js versions: Step 4: Installing Node.js and Switching Versions: To install the latest Node.js version: To install the latest LTS Node.js version: To install a specific Node.js version, like v14.15.3: Step 5: View Installed Node.js Versions:…

min read

Prerequisites:

  • Supported operating system for Node.js.
  • Access to the root user account (or admin account with root privileges)

Linux Installation:

Step 1: Open Terminal

apt-get update -y
apt-get upgrade -y

Step 2: Installing nvm:

  • Go to the GitHub page for nvm.
  • Copy and paste the install script into your command line:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
  • Press Enter. After installation, close and reopen your terminal.

Step 3: Check nvm Installation:

nvm --version
nvm -v

To view available Node.js versions:

nvm list-remote

Step 4: Installing Node.js and Switching Versions:

To install the latest Node.js version:

nvm install node

To install the latest LTS Node.js version:

nvm install --lts

To install a specific Node.js version, like v14.15.3:

nvm install 14.15.3

Step 5: View Installed Node.js Versions:

nvm ls

Switching Between Versions:

To switch to another installed Node.js version:

nvm use 17.1.0

For common switches:

nvm use node           # latest version
nvm use --lts          # latest LTS version
nvm use 14.15.3        # specific version

Running Applications with Specific Versions:

To run with a specific version:

nvm run 17.5.0 app.js

To run with PATH pointing to a version:

nvm exec 17.5.0 node app.js

Setting Default Node.js Version:

To set a default version:

nvm alias default 14.15.3

Or, to set the latest version as default:

nvm alias default node