NPM is the default package manager for Node.js. This means NPM is usually not installed in isolation, but is installed as a component when installing Node.js.
Therefore, before you can use NPM, the first step is to ensure Node.js is correctly installed on your system.
If you don’t have Node.js installed yet, it is available for different operating systems and can be downloaded from the official website (https://nodejs.org).
Once you have downloaded the installer for your operating system, proceed to run it and follow the steps in the installation wizard. During the installation, NPM will be automatically added as part of the process.
Verify Node.js Installation
To verify if you have Node.js correctly installed, and which version, simply open a terminal or command line and type the following command,
node -v
If NPM is installed correctly, it will show us the version of NPM installed on our system.
v16.15.0
If instead of a version number it says it doesn’t recognize the command, it means you need to install Node.js.
Update NPM
It’s important to keep NPM updated to ensure we have access to the latest features and bug fixes. Let’s see how we can update NPM.
To update NPM globally, which is generally what we want to do, we use the following command:
npm install -g npm@latest
This command installs the latest version of NPM over the current version and makes it available from the command line from any location.
npm install -g npm@lts
While this will install the latest stable version (LTS = Long Time Support).
If you want to update NPM only for a specific project, you must run the following command in the project’s root folder:
npm install npm@latest
npm install npm@lts
This will update the version of NPM associated with the current project, without affecting other global NPM installations on your system.
