How to Update npm Version? [Update npm Package to Latest Version]

Do you know how to update npm version to the latest version for better productivity? This article will guide you; How you can update npm package.

Updated: 02 Nov, 23 by Antoniy Yushkevych 6 Min

List of content you will read in this article:

Welcome to a comprehensive guide on how to update your NPM (Node Package Manager) version. NPM plays a vital role in the world of web development, acting as the package manager for Node.js, and is an essential tool for JavaScript developers. Regular updates to NPM ensure that you have access to the latest features, security enhancements, and bug fixes, keeping your projects running smoothly and securely.

Updating NPM (Node Package Manager) is a straightforward process, and one of the most convenient methods is using NPM itself.

  • Open Your Command Line Interface (CLI): Launch your CLI, whether it's the Windows Command Prompt, macOS Terminal, or a Linux terminal.
  • Check Your Current NPM Version: Before updating, it's a good practice to check your current NPM version. You can do this by running the following command:

npm -v

  • Update NPM: To update NPM using NPM itself, simply use the following command:

npm install -g npm

This command tells NPM to install the latest version of NPM globally (hence the `-g` flag).

  • Wait for the Update: NPM will automatically download and install the latest NPM version. Depending on your internet connection speed, this process should only take a few moments.
  • Verify the Update: After the update is complete, run the following command to verify that NPM is now running on the latest version:

npm -v

The CLI should display the new version of NPM.

For Windows users, updating NPM (Node Package Manager) is a straightforward process that can be accomplished using the Node.js Installer.

  • Download the Latest Node.js Installer: Visit the official Node.js website at nodejs.org and choose the "LTS" (Long-Term Support) version, which is recommended for most development purposes. Click on the "Windows Installer" to download the installer.
  • Run the Installer: Once the installer is downloaded, double-click the executable file to run the Node.js Installer. This will launch the installation wizard.
  • Select "Modify" Installation: In the installation wizard, you will be presented with an option to choose the components to modify. Select the "Modify" option.
  • Update npm: After selecting "Modify," you will see a list of components to modify. Find and check the box next to "npm" in the list.
  • Complete the Modification: Click the "Next" button to proceed with the modification. The installer will update NPM to the latest version. Follow the on-screen prompts to complete the process.
  • Verify the Update: After the modification is complete, open your Command Prompt (CMD) or PowerShell and type the following command to verify that NPM has been updated successfully:

npm -v

The CLI should display the new version of NPM.

macOS users have a powerful package manager called Homebrew at their disposal, which provides a convenient way to update NPM (Node Package Manager) to the latest version. Here's a step-by-step guide on how to update NPM using Homebrew:

  1. Open Terminal: Launch the Terminal application on your macOS system. You can find it in the "Utilities" folder within the "Applications" directory.
  2. Install Homebrew (if not already installed): If you haven't already installed Homebrew, you can do so by running the following command in your Terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Follow the on-screen instructions to complete the Homebrew installation.

  • Check Your Current NPM Version: Before updating NPM, it's a good practice to check your current NPM version. You can do this by running the following command:

npm -v

  • Update NPM: To update NPM using Homebrew, execute the following commands one by one:

brew update

brew upgrade npm

The first command, `brew update`, ensures that Homebrew itself is updated. The second command, `brew upgrade npm`, updates NPM to the latest version.

  • Verify the Update: After the update is complete, run the following command to verify that NPM is now running on the latest version:

npm -v

The Terminal should display the new version of NPM.

Linux users often prefer using NVM (Node Version Manager) to manage Node.js and NPM installations.

  • Open Your Terminal: Launch your terminal application. Depending on your Linux distribution, you may use Terminal, Konsole, or another terminal emulator.
  • Check Your Current NPM Version: Before updating NPM, it's a good practice to check your current NPM version. You can do this by running the following command:

npm -v

  • Install NVM (if not already installed): If you haven't already installed NVM, you can do so using a one-liner script. Open your terminal and run the following command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

This will download and install NVM. Make sure to use the latest NVM version by checking the NVM GitHub repository (https://github.com/nvm-sh/nvm) for the latest release.

  • Close and Reopen the Terminal: After installing NVM, it's a good practice to close and reopen your terminal or run the following command to apply the changes to your current session:

source ~/.bashrc

Make sure to replace `~/.bashrc` with the appropriate file for your shell if you're not using Bash.

  • Install and Use the Latest Node.js Version: Use NVM to install the latest LTS (Long-Term Support) version of Node.js, which also includes NPM. Run the following commands:

nvm install --lts

nvm use --lts

This installs and activates the latest Node.js LTS version, which includes the latest NPM version.

  • Verify the Update: After the update is complete, run the following command to verify that NPM is now running on the latest version:

npm -v

Your terminal should display the new version of NPM.

Updating NPM (Node Package Manager) is a fundamental practice for web developers, ensuring that your Node.js projects remain secure, efficient, and up-to-date with the latest features. In this comprehensive guide, we've explored various methods to update NPM, catering to different platforms and preferences.

Antoniy Yushkevych

Antoniy Yushkevych

Master of word when it comes to technology, internet and privacy. I'm also your usual guy that always aims for the best result and takes a skateboard to work. If you need me, you will find me at the office's Counter-Strike championships on Fridays or at a.yushkevych@monovm.com
user monovm

Sasha Reynolds

2024, Sep, 24

Thanks for this detailed guide on updating NPM! It's really helpful to have all the different methods outlined for various platforms. Keeping NPM updated is definitely crucial for utilizing the latest features and maintaining project security. I've often struggled with finding reliable instructions, but this breakdown makes it so much clearer. Appreciate the effort put into making this comprehensive resource!

user monovm

Godfrey Bailey

2024, Nov, 24

Thanks for sharing this comprehensive guide! It's a great resource for both new and experienced developers looking to keep their NPM updated smoothly across different platforms. The step-by-step instructions make it super easy to follow, and the inclusion of alternative methods ensures everyone can find a solution that works for their setup. Keeping our tools updated is crucial for security and performance, so this is definitely helpful. Looking forward to more such detailed guides!