How to Install Node JS and NPM in Windows 10 and Ubuntu 20.04 correctly {Update 2023}

This post is for all javascript lovers. If you want to know “How to install node js and npm” in Windows and Ubuntu. You have landed on the right page. I have included all possible options to install node.js and npm in your favourite OS. These methods are really easy. All the commands output are also attached for your reference.

I am sure if you will follow this post step by step. You will be able to install node js and npm easily even if you are a newbie.

What will you learn in this post –

What is node Js and NPM

The NPM stands for the node package manager. It is the default package manager for Node.js. Basically, Node.js is a JavaScript runtime environment. Node.js allows developers to build scalable network application quickly. NPM is a client helps to access and browse the npm registry via the npm website. NPM registry is the repository of public and private packages online. Alternately, ied, pnpm, npmd and yarn can be used to access npm registry.

As per Wikipedia website

npm, Inc. is a subsidiary of GitHub, an American multinational corporation that provides hosting for software development and version control with the usage of Git.

npm-details-wiki

There are couple of ways to install node.js and npm in Windows.

  1. GUI (manual method)
  2. Using chocolatey (Powershell)

Please make a note, npm (node package manager) will auto install in windows 10 with node.js.

1:- How to install node js on Windows 10

Step1:- Download node js

Download Node.js software from nodejs.org website. The latest LTS version is node-v14.15.3. Package npm is in-built. You don’t need to install it separately. If you own an old version of windows, select 32-bit version of node.js installer. Otherwise, choose 64-bit in all other cases.

I will select 64-bit version.

Download-node-js

Step1.1

After download of node js completes. Visit your download directory.

Nodejs-latest-version

Step2:- Install Node.js and npm

Double click installer node-v14.15.3-x64.msi. This will start Node Js installation wizard.

Click Next

node.js-setup

Step2.1

Select “I accept the terms in the license Agreement” box. It confirms that you agree with node.js end user license agreement. Click Next

node-js-EULA

Step2.2

Select the destination folder for node.js installation. Default location of node.js is “C:\Program Files\nodejs\“. In case, you want to select a custom location. Click on change and browse for your preferred install location.

Select – Next.

node-js-installation-folder

Step2.3

Select node.js features. I will suggest you leave it default. Also, npm (node package manager) is part of features. So you don’t need to install it separately.

Space required to install these node js and npm features need 143MB capacity.

Following features will install by default –

  • Node.js runtime
  • Npm package manager
  • Online documentation shortcuts
  • Add to Path

Click Next

node-js-features

Step2.4

Choose an optional tool to compile native modules, if required. Some npm modules need to be compiled from C/C++. To install these modules, you will need python and Visual studio build tools.

Choose box “Automatically install the necessary tools option“. You can visit https://github.com/nodejs/node-gyp#on-windows to install it later manually. We will discuss the chocolatey software in the next section.

In my case, i have not selected this option.

Choose Next.

node-js-dependent-native-modules

Step2.5

Now you are ready with final node js step. You can click “Back” to review or change your node.js installation settings.

Click Install.

How-to-install-node-js-in-windows

Step2.6

Select “Yes” to allow windows to run Node.js.

allow-node-js-installation

Step2.7

Sit back and relax. it will take couple of minutes to complete node.js installation.

validating-node-js-and-npm-install

Step2.8

Click Finish. You are done with node.js installation now.

finish-node.js-wizard

Step3:- Check Node.js and npm version

Step3.1

Open command prompt with “run as administrator”. Run node and npm command.

Check node js version

C:\> node -v 

Check npm (node package manager) version

C:\> npm -v
check-node-js-version

In my case, node.js version is v14.15.3 and npm is 6.14.9

Nowadays Microsoft recommends to Node js and NPM installation in WSL (Windows Subsystem for Linux). Follow this post to learn WSL and how to install Ubuntu on Windows.

1.a:- How to uninstall node js in Windows 10

In case you have old version of node.js or npm installed and want to remove it. Follow these steps-

Step1: Open add remove programs

Go to “Add or remove programs” from search window. Click open.

add-remove-programs-windows

Step2: Find and Uninstall node js

Find node.js and click uninstall.

uninstall-node-js

it will take couple of minutes to get clean from machine.

remove-node-js

It will also remove npm (node package manager).

Video – How to install Node js and npm in windows 10

2:- How to install node js in Windows using chocolatey {Powershell}

There is one more way to install node.js and npm using chocolatey. It is a software management solution. You will need PowerShell to run these commands.

Follow these commands one by one –

Step1:- Open PowerShell as admin

Type PowerShell in search box and open it as run as administrator.

Step2:- Set Execution policy

The execution policy is “restricted” by default in PowerShell. This policy will not allow you to run scripts. So you need to change it to “AllSigned“. So that it allows to download and run chocolatey commands.

C:\> Set-ExecutionPolicy AllSigned
set-execution-policy-powershell

Step3:- Download and Install Chocolatey using PowerShell script

Copy and paste this script to download and install chocolatey software in Windows. It will install the latest version of the chocolatey package.

It also download 7-zip tool and install it prior to extraction. You can safely ignore warnings while installing chocolatey.

C:\> Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
install-chocolatey-using-powershell

If you get warning “Not setting tab completion: Profile file does not exist at <location>”. Make a folder on that location. it will help you to complete chocolatey commands using Tab. For example, I will make a folder in “C:\users\Dev\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1”.

Step4:- Install node.js using choco command

Run choco command to download and install node js and npm using PowerShell. You can use -Y option for the non-interactive run.

> choco install nodejs

Use –force option, in the case earlier node.js installation failed. This will install the latest node.js version available.

To install specific version, give details in command. For example, i have given version 12.10.0.

> choco install nodejs --version=12.10.0
install-nodejs-using-chocolatey-powershell

Step5:- Check node js and npm version

Check node js version

> node --version

Check npm version

> npm --version
check-node-and-npm-version

Step6 (optional):- Install angular CLI

This step is optional and only need to run, if you need angular CLI. NPM command will help to download and install angular package.

Open command prompt with “run as administrator” rights. Then run npm command to install angular/cli.

option i – to install package

-g option – for global in npm command.

> npm i -g @angular/cli
install-angular-cli

or use @version to install version, you need. For example 1.8.2

npm i -g @angular/cli@1.8.2

How to install node js in Linux

Node js can be installed in Linux using two ways. One is from the official repository and second from NodeSource repository. These steps are applicable to Ubuntu 18.04 and 20.04 distro.

1# How to install node js in Ubuntu 20.04 using Ubuntu repository

Installation of node js and npm in Ubuntu is a two-step process. It’s always recommended to install node js first. it’s really easy. Follow these steps –

Step1:- Open terminal and update Ubuntu repository

Open terminal with Ctrl + Alt + T and update repository.

$ sudo apt-get update
apt-get-update

Step2:- Install node js using CLI

Run apt-get command to install nodejs package. Make a note, npm is suggested package.

$ sudo apt-get install nodejs
how-to-install-node-js-in-ubuntu-20.04

Step3:- Check Node version

Once installation done. Check node.js version

$ node -v

or

$ node --version
check-node-js-version

Step4:- Install npm in Ubuntu 20.04 using apt

Now let’s install node package manager (npm) which is required by Node Js.

$ sudo apt-get install npm
How-to-install-npm-in-ubuntu-20.04

Step5:- Check npm version

Check npm version

$ sudo npm -v 

or

$ sudo npm --version
check-npm-version

How to uninstall node js in Ubuntu

Remove node js from Ubuntu using these simple steps –

Step1:- Open terminal and run remove node js from ubuntu

Open terminal Ctrl + Alt + T and run apt-get command

$ sudo apt-get remove nodejs
uninstall-node-js-in-ubuntu

How to uninstall npm in Ubuntu

Step2:- Open the terminal and run remove npm

Open terminal Ctrl + Alt + T and run apt command to remove npm

$ sudo apt-get remove npm
uninstall-npm-in-ubuntu

2# How to install node js in Ubuntu using NodeSource repository

If you want to install a newer version of node.js and npm. Then you need to connect to NodeSource repository. Follow these simple steps-

Step1:- Open the terminal and update Ubuntu package manager

Open terminal and and run apt command to update package manager.

$ sudo apt-get update

Step2:- Install dependent python libraries

Install dependent Python libraries with apt-get command

$ sudo apt-get install python-software-properties

Step3:- Add node source PPA

Add node js repository to system. If you want to add it for version 14. Change 15.x to 14.x in command.

$ curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash -
add-nodesource-repository

Tip

If you get “curl” not found error. Install curl utility first.

$ sudo apt install curl
how-to-install-curl-ubuntu

Step4:- Install node js and npm packages in Ubuntu 20.04

Install node js and npm in Ubuntu using apt-get command. You don’t need to install npm separately in this case. Checkout this post on more ways to install packages in Ubuntu.

$ sudo apt-get install -y nodejs
Install-node-js-and-npm-in-ubuntu-20.04

Step5:- Check Node and npm version in Ubuntu

Check node js version

node -v

or

node –version

Check npm (node package manager) version

npm -v

or

npm –version

check-node-js-version-in-ubuntu

Step6 (optional):- Install build essential tools

Install build tools to compile and install native add-ons. This is optional and depends on your need.

$ sudo apt-get install -y build-essential 

So, you have installed node js and npm in Ubuntu successfully.

Video – How to install Node js and npm in Ubuntu 20.04

Frequently Asked Questions

Is node JS safe to install?

Yes, installing node js is safe. Make sure you download node js software from nodejs.org website or authentic vendor repository only.

How to install node js as Windows service?

node-js-as-windows-service

Download node-windows as a standalone module. The node-windows has a utility to run Node.js scripts as Windows services.

Which is the Best node js setup?

It’s always recommended to install latest (LTS) node js setup. Currently latest LTS version of node js is 14.15.3 (includes npm 6.14.9). LTS stands for long term support.

How to install the previous version of node js?

install-the-previous-version-of-node-js

1.) Visit “https://nodejs.org/en/about/releases/
2.) Scroll down and select your version
3.) Download and install.

Conclusion

There are multiple ways to download and install node js and npm in your favourite operating system. I have shown you the easiest ways to do it. You must be a happy soul and should be ready to work on your JavaScript. Let me know in comments if you still face any issue.

I will be happy to assist you.

Dev

I'm Dev, your friendly neighbourhood Tech Savy. I spend my days with gadgets, servers, and the occasional laugh-inducing software mishap. Think of me as your tech-savvy, glitch-prone buddy. If you've got questions, feedback, or just need someone to blame when your Wi-Fi goes haywire, I'm your guy!

This Post Has 5 Comments

  1. Josephine

    Hi !
    This is a very interesting and well explained post !
    I followed what was shown but failed to update node and npm. I have a Window 10 with Linux and Ubuntu installed on it.
    I currently have version 3.10.10 of npm and 14.15.0 of node and when I try to update them I have this problem :
    npm ERR! Linux 5.4.72-microsoft-standard-WSL2
    npm ERR! argv “/home/josephine/.nvm/versions/node/v14.15.0/bin/node” “/home/josephine/.nvm/versions/node/v14.15.0/bin/npm” “install” “-g” “npm”
    npm ERR! node v14.15.0
    npm ERR! npm v3.10.10
    npm ERR! cb.apply is not a function
    What could be the solution here? Thanks in advance.
    Thanks !
    Josephine

    1. Dev

      Hi Josephine,

      Thanks and happy to know that you liked this article. I have few questions –
      1.) Are you trying to update npm v3.10.x to the latest? Have u tried removing this legacy version and then installing latest version fresh?
      2.) Looks like you are using WSL2. Can you please confirm ubuntu version? On which you are trying to upgrade NPM and node?

      I will try to replicate this issue in my PC, once you will reply and will try to solve it.

      Thanks
      Dev

      1. Josephine

        Yes I’m trying to update npm v3.10.x to the latest version. I tried removing npm but it doesn’t work and I get the same error message coming back (npm ERR! Linux 5.4.72-microsoft-standard-WSL2…).
        I’m using Ubuntu 20.04.1 LTS.

          1. Josephine

            Ok thanks, I tried this link but it doesn’t work.

Comments are closed.