In this section, we'll explain how to install both Node.js and npm on your machine.
Installing Node.js and npm
Windows
Go to the official website of Node.js: https://nodejs.org and download the latest LTS (short for Long Term Support) release; you'll find the download links directly on the home page. This is preferred at work, but you may also install the latest and greatest.
Once downloaded, run the installer as follows:
- On the first screen, select where to install and click on Next:
On the next screen, make sure that npm package manager is selected so that npm gets installed as well.
- Also, check that Add to PATH is selected:
- On the next screen, click on Install:
The installation should then get going:
- Once completed, click on Finish:
Congratulations, you now have both node and npm on your machine.
In addition, Node.js also comes with a pre-configured shell called Node.js:
If you open up Command Prompt (for example, with cmd.exe), then you should be able to execute node and npm and retrieve their respective versions:
C:\Users\username>node --version
v8.12.0
C:\Users\username>npm
5.8.0
It should also work fine within PowerShell if you prefer that:
PS C:\Users\username>node --version
v8.12.0
PS C:\Users\username>npm --version
5.8.0
The exact version numbers don't matter that much as this evolves all the time, but if you want to be sure to have the exact same behavior, then you can try to match ours.
Git BASH
If you follow our advice and try to use Git BASH, then you might be disappointed at first.
Execute the following command:
$ node --version
When you do so, you should get back the following error: bash: node: command not found.
Changes to the Windows path are not immediately picked up by Git BASH; for this to happen, sometimes a reboot is necessary (Windows, eh?). If rebooting the operating system doesn't solve the issue, then you can also edit your user profile through the .bash_rc file and modify the path manually. For example, if you've installed Node.js under C:/nodejs, then you can add this to your Bash profile: PATH=$PATH:/c/nodejs. Once done, you should be able to execute both node and npm.
Linux (shell)
On Linux, the installation can easily be done using the Terminal with the following steps:
- First of all, open up the Terminal.
- Next, install curl as you'll need it to install Node.js: sudo apt install curl
- Then, install Node.js from the NodeSource (https://nodesource.com) repository:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
- You should now have both node and npm installed. Here's a link to the reference installation guide for Debian-and Ubuntu-based distributions: https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions.
Let's now see how to update npm.