Language: EN

como-instalar-actualizar-npm

How to install or update NPM

NPM is the default package manager for Node.js. In other words, NPM is typically not installed in isolation, but is installed as a component when installing Node.js.

Therefore, before we can use NPM, the first step is to ensure that Node.js is correctly installed on our system.

If you haven’t installed Node.js 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 of 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 it is, 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 tells you that it does not recognize the command, you need to install Node.js.

Update NPM

It is 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.

Update NPM Globally

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 in the command console from any location.

 npm install -g npm@lts

While this will install the latest stable version (LTS = Long Time Support)

Update NPM Locally

If you want to update NPM only for a specific project, you should run the following command in the root folder of the project:

npm install npm@latest
 npm install npm@lts

This will update the version of NPM that is associated with the current project, without affecting other global installations of NPM on your system.