To install node on Windows I recommend that you use a package manager. This can be either Chocolatey or Scoop.
If you have neither of these installed then let's go ahead and install Scoop. To do that you need to open PowerShell. Click Start and type PowerShell into the search bar. Then double-click to open the application.
Once inside PowerShell, you will need to run this command:
iwr -useb get.scoop.sh | iex
When the installation is complete you can verify the install by running this command:
Now we are ready to install node. To do that run the following command:
scoop install nodejs
Once complete you can check that the installation has worked by running:
Now that you have node installed you may need to upgrade it in the future. There are also times when you need to run a specific version of node. To do this we can use a node version manager.
How to Install Node.js on Linux
The easiest way to install node on Linux is to use the Advanced Package Tool (APT). We will look at installing node on both Ubuntu and Debian-based Linux distros.
The default source for node.js in APT is a bit outdated so we need to give a new source. After adding the source you can then install node.
Now that you have node installed you can verify that it is working by running:
Now that you have node.js installed, make sure to install a node version manager. This allows you to easily upgrade node to the latest version.
How to upgrade Node.js
Once you have Node.js installed you may need to upgrade it or change the version. You can only have a single version of node installed at once so how can you do it?
When you install node it also installs a program called NPM which stands for Node Package Manager.
You can use npmjs.com/ to find packages that you might want to install. One of these packages is called n. n will let you change the version of node that is running.
To install n we need to run the following command:
npm i n -g
Here we have told NPM to install the n package globally (-g). This means that you can now access the n from the command line. To verify the install you can run:
You should see the version number printed in the command or terminal.
Now there are a few useful commands. The first is to upgrade node to the latest version to do this run:
n will then fetch the latest version of node and install it. Once complete you can verify the install by checking the node version:
By installing the latest version of node you will get all the features but often there are bugs too. To install the most stable version you should install the Long Term Support (LTS) version of node. To do that with n run this command:
You can also install a specific version of node. For example, if we wanted to install version 10.16.0 of node then we would run:
Now you have an easy way of upgrading or running a specific version of node.
Wrapping Up, How to Install Node.js
We have looked at how to install node.js on Windows, Mac OS X and Linux.
With Mac OS X we used the brew which is a package manager. Once you installed brew it is easy to install node with a single command.
The Windows installation also used a package manager called Scoop. With Scoop installed you can open PowerShell and install node.js.
Finally, we looked at Linux and upgraded the node.js source for APT and then installed node via apt-get.
You can use n the node version manager to upgrade node on all operating systems. This allows you to specify a specific version of node to run. You also have the option of upgrading to the latest version of node or the Long Term Support version.
This makes it much easy to manage multiple versions of node on a computer.