Installing Node.js

Last updated on

Installing node js on Windows, Ubuntu, or macOS. You need to pick the version of Node.js that you want to install.

Usually, you have two main choices:

  • LTS (Long-Term Support) Version: This one is more stable and will be supported for longer. It is the safest bet to ensure fewer surprises and be a little more reliable.
  • Current Version: This is the version with all the new fancy custom rules, but it has only had so much testing done — may have a few bugs.

Let’s get started on how to install Node.js on the Windows operating system.

Installing Node.js on Windows

The very first thing you need to do is get Node. js software. It’s the official Node. js web page: https://nodejs.org/en/download/.

After the link is opened more installers are shown. Downloading Node — Just Checkmark on the “Download Node. js” button.

Download Node.js Installer

Select the installer according to your System, maybe 32bits or 64-bit.

When your download is complete, run the file as an admin to start installing. Look at the prompts on the screen.

However, be sure to confirm the license agreement and choose an installation folder if you wish.

The setup wizard will immediately walk you through a couple of options:

  • Installing required tools OR if prompted check the box labeled Automatically install necessary tool to save yourself from troubles.
  • Once the installation process is complete question is how do you Query the command using the Command line Interface (CLI)to find out the version of software on your OS like so:
node -v

This installer is an NPM package (installed automatically as part of the process).

To check the NPM version, just run the command below.

npm -v

Here is an image showing how to verify the NPM and Node.js versions for each command.

Check Nodejs Version

If that is the case, congratulations! You have successfully installed Node.js on Windows. Let’s move on to the following section to learn how to install node.js on Ubuntu.

Installing NPM and Setting Up Node.js on Ubuntu

When you’re ready to dive into JavaScript development on the Ubuntu operating system, setting up Node.js and NPM (Node Package Manager) is your first step.

Therefore, very important to update the package repository before even installing any new software. It is in order to keep you updated on the latest versions and offer our best installation ceremony.

Open your terminal and run this command:

sudo apt update

This command refreshes your system software list and sets the stage for a smooth installation.

Ubuntu’s package repository already contains Node.js, so you can install it directly using the apt package manager. To install Node.js along with npm, use the following command:

sudo apt install nodejs npm

Then, you can verify the installation by checking the versions of Node.js and NPM, as mentioned earlier:

node -v
npm -v

Anyway, In the following section, you will learn how to install NPM and Node.js on the macOS operating system. Let’s dive in.

Installing Node.js on macOS

It is the same process as in Ubuntu OS, just follow the following steps:

Firstly, you need to open the terminal on your macOS by pressing the two keys on your keyboards Command+Space. Then just type “Terminal” in the search bar.

Once you see the Terminal open you need to install Homebrew which is the package manager of macOS. Here is the command.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Then run the below command to start installing Node.js.

brew install node

Then, confirm that the installation was successful by checking the versions of Node.js and npm with this command:

Once the installation process is finished, you have to check the version number that is already installed on your operating system, and that can be done by the following command.

node -v
npm -v

Congratulations! You have successfully installed Node.js on macOS. In the following section, I will show you another method to install NPM and Node.js on all operating systems using the binary package. Let’s get started.

Install Node.js and NPM Using the Binary Package on Windows

To start the installation using the binaries, open the official Node.js website and then select the binary package that works according to your operating system from the listed list there.

Installing Node.js using Binary Package

Once you download the target package you need to extract it from the compressed file. For this example, we downloaded the 64-bit binary package named “node-v16.15.1-win-x64.”.

download nodejs binary package

After moving the folder, copy the path of its new location.

Extract Node.js Binary Package

Then, add this path to the Environment Variables by opening the “Environment Variables” window. You can do this by following the below steps:

Right-click on “My Computer” with your mouse and choose “Properties.”

advanced system settings

Scroll down and click on “Advanced System Settings” to open the “System Properties” window.

Click on the “Advanced” tab and then click the “Environment Variables” button.

system properties 

Now, click on “Path” and then click the “Edit” button.

variables environment

Next, add the new path to the list of variables, as illustrated in the images below.

add new variable to env

In the next section, you will learn how to update Node.js using NPM. Let’s move on.

Updating Node.js Using the Node Package Manager (NPM)

NPM, or Node Package Manager, lets you update Node.js with a package from the NPM registry called “n.” This package manages different versions of Node.js. To install “n,” use the command listed in the npm registry.

npm install n

To update or install Node.js using the “n” package, you need to run one of the following commands:

n lts
n latest

In the following section, you will learn another method to update or install a specific version of Node.js on your operating system using NVM.

Set Up or Update Node.js Using Node Version Manager (NVM)

NVM stands for Node Version Manager. This tool helps manage different versions of Node.js. If you have multiple versions installed, you can switch between them using NVM commands.

If you don’t have NVM installed on your computer, go to the NVM tutorial for guidance on how to install it.

Once you have confirmed that NVM is installed on your machine, you can run the following command to install a specific version of Node.js:

# NVM Command 
nvm install {The New Version} --reinstall-packages-from={The Old Version}

# Example
nvm install 16.15.1 --reinstall-packages-from=10.4

Anyway, Let’s move on to the next section to learn how to check the current version of Node.js on your machine.

Verify The Node.js and NPM Installation

Additionally, to check the version of Node.js you downloaded or to ensure the installation was successful, you need to run the following command using the command prompt.

So to open it, go to the Start menu, type “command prompt” in the search bar, and click to open the application.

temp snip

Here is the command to verify the Node.js installation:

node -v

And to verify the NPM version, use the following command:

npm -v

NPM allows you to update its package on your machine using a global command. Let’s explore how to do that in the following section.

Update Node Package Manager (NPM)

You can use the npm command to update npm itself. If you are using Ubuntu or macOS, please precede the following command with ‘sudo’ to grant administrative privileges.

npm update npm@latest -g
npm update latest version

If you look at the image above, you will see a warning message suggesting you use --location=global instead of the outdated -g flag.

Anyway, when you see this warning message, run the below command.

npm update npm@latest --location=global

Accordingly, you will see a new message stating “up to date,” which indicates that we have already installed the latest version of NPM.

Otherwise, it will display a notice listing the updated and removed packages. For example:

npm update npm g

Let’s summarize it.

Wrapping Up

The installer of Node.js lets you run JavaScript on your computer. It comes in two main types: the LTS Version and the Current Version. So the recommended version to install is the LTS version.

Setup Node.js on Windows:

  • Download the Installer: Go to the Node.js website (https://nodejs.org/en/download/) and download the installer suitable for your Windows version (32-bit or 64-bit).
  • Run the Installer: Open the downloaded file and follow the on-screen instructions. Agree to the license, choose where to install, and let the installer download the necessary tools automatically.
  • Check the Installation: After installing, you can check if Node.js is working by typing node -v in the Command Line Interface to see the version number.

Installing Node.js on Ubuntu

  • Open the terminal and update your package list with sudo apt update.
  • Use the command sudo apt install nodejs npm to install both Node.js and NPM.
  • Then check the version that is installed on your machine by this “node -v”.

Installing Node.js on macOS

  • Open the Terminal, and install Homebrew by running /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)".
  • Use Homebrew to install Node.js and NPM by typing brew install node.
  • And then check the version using this command node -v.

Thank you for reading. Happy Coding!

Share on: